mpviewplugins/mpcollectionviewplugin/src/mpcollectionpopuphandler.cpp
changeset 58 ed94e1e8390e
parent 54 c5b304f4d89b
child 59 cd9e40a08dda
equal deleted inserted replaced
54:c5b304f4d89b 58:ed94e1e8390e
    32 #include "mpcollectiondatamodel.h"
    32 #include "mpcollectiondatamodel.h"
    33 #include "mpcollectiontbonelistdatamodel.h"
    33 #include "mpcollectiontbonelistdatamodel.h"
    34 #include "mpcollectionpopuphandler.h"
    34 #include "mpcollectionpopuphandler.h"
    35 #include "mptrace.h"
    35 #include "mptrace.h"
    36 
    36 
    37 const int KNullIndex = -1;
       
    38 const int KSongsToDisplayProgressDlg = 100;
    37 const int KSongsToDisplayProgressDlg = 100;
    39 
    38 
    40 // Popups launched by this class
    39 // Popups launched by this class
    41 const QString KContextMenu = QString( "ContextMenu" );
    40 const QString KContextMenu = QString( "ContextMenu" );
    42 const QString KProgressDialog = QString( "ProgressDialog" );
    41 const QString KProgressDialog = QString( "ProgressDialog" );
    72     public:
    71     public:
    73         MpPopupHandlerPermanentData( QObject *parent=0 );
    72         MpPopupHandlerPermanentData( QObject *parent=0 );
    74         virtual ~MpPopupHandlerPermanentData();
    73         virtual ~MpPopupHandlerPermanentData();
    75         void clear();
    74         void clear();
    76     public:
    75     public:
    77         MpMpxCollectionData         *mIsolatedCollectionData;        // Not own
    76         MpMpxCollectionData         *mCollectionData;      // ownership depends on mIsolatedOperation
    78         QAbstractItemModel          *mAbstractItemModel;             // Own
    77         QAbstractItemModel          *mAbstractItemModel;   // ownership depends on use case, parented.
    79         QList<int>                  mSelectedItems;
    78         QList<int>                  mSelectedItems;
    80         QString                     mOriginalName;
    79         QString                     mOriginalName;
    81         int                         mContextMenuIndex;
    80         QModelIndex                 mContextMenuModelIndex;
       
    81         bool                        mIsolatedOperation;
    82 };
    82 };
    83 
    83 
    84 /*!
    84 /*!
    85  Constructs the popup handler permanent data.
    85  Constructs the popup handler permanent data.
    86  */
    86  */
    87 MpPopupHandlerPermanentData::MpPopupHandlerPermanentData( QObject *parent )
    87 MpPopupHandlerPermanentData::MpPopupHandlerPermanentData( QObject *parent )
    88     : QObject( parent ),
    88     : QObject( parent ),
    89       mIsolatedCollectionData( 0 ),
    89       mCollectionData( 0 ),
    90       mAbstractItemModel( 0 ),
    90       mAbstractItemModel( 0 ),
    91       mContextMenuIndex( KNullIndex )
    91       mContextMenuModelIndex(),
       
    92       mIsolatedOperation( false )
    92 {
    93 {
    93       TX_ENTRY
    94       TX_ENTRY
    94       mSelectedItems.clear();
    95       mSelectedItems.clear();
    95       mOriginalName.clear();
    96       mOriginalName.clear();
    96       TX_EXIT
    97       TX_EXIT
   113 void MpPopupHandlerPermanentData::clear()
   114 void MpPopupHandlerPermanentData::clear()
   114 {
   115 {
   115     TX_ENTRY
   116     TX_ENTRY
   116     mSelectedItems.clear();
   117     mSelectedItems.clear();
   117     mOriginalName.clear();
   118     mOriginalName.clear();
   118     mContextMenuIndex = KNullIndex;
   119     mContextMenuModelIndex = QModelIndex();
   119     if ( mIsolatedCollectionData ) {
   120     if ( mIsolatedOperation ) {
   120         MpEngineFactory::sharedEngine()->releaseIsolatedCollection();
   121         mIsolatedOperation = false;
   121         mIsolatedCollectionData = 0;
   122         if ( mCollectionData ) {
   122     }
   123             MpEngineFactory::sharedEngine()->releaseIsolatedCollection();
   123     if ( mAbstractItemModel ) {
   124             mCollectionData = 0;
   124         delete mAbstractItemModel;
   125         }
   125         mAbstractItemModel = 0;
   126     }
   126     }
   127 
       
   128     //deleted by parenting if owned
       
   129     mAbstractItemModel = 0;
       
   130 
   127     //clearing any child Objects.
   131     //clearing any child Objects.
   128     foreach (QObject* child, children()) {
   132     foreach (QObject* child, children()) {
   129         child->deleteLater();
   133         child->deleteLater();
   130     }
   134     }
   131     TX_EXIT
   135     TX_EXIT
   172 }
   176 }
   173 
   177 
   174 /*!
   178 /*!
   175  Default view context menu.
   179  Default view context menu.
   176  */
   180  */
   177 void MpCollectionPopupHandler::openDefaultViewContextMenu( int index, const QPointF &coords )
   181 void MpCollectionPopupHandler::openDefaultViewContextMenu( const QModelIndex &index, const QPointF &coords )
   178 {
   182 {
   179     TX_ENTRY
   183     TX_ENTRY
   180 
   184 
   181     if ( mView->isActivated() ) {
   185     if ( mView->isActivated() ) {
   182 
   186 
   216                 break;
   220                 break;
   217             case ECollectionContextPlaylists:
   221             case ECollectionContextPlaylists:
   218                 contextMenu = new HbMenu();
   222                 contextMenu = new HbMenu();
   219                 action = contextMenu->addAction( hbTrId( "txt_common_menu_open" ) );
   223                 action = contextMenu->addAction( hbTrId( "txt_common_menu_open" ) );
   220                 action->setObjectName( KOpen );
   224                 action->setObjectName( KOpen );
   221                 if ( !mMpEngine->collectionData()->isAutoPlaylist( index ) ) {
   225                 if ( !mMpEngine->collectionData()->isAutoPlaylist( index.row() ) ) {
   222                     action = contextMenu->addAction( hbTrId( "txt_common_menu_delete" ) );
   226                     action = contextMenu->addAction( hbTrId( "txt_common_menu_delete" ) );
   223                     action->setObjectName(KDelete);
   227                     action->setObjectName(KDelete);
   224                     action->setEnabled( !usbBlocked );
   228                     action->setEnabled( !usbBlocked );
   225                     action = contextMenu->addAction( hbTrId( "txt_common_menu_rename_item" ) );
   229                     action = contextMenu->addAction( hbTrId( "txt_common_menu_rename_item" ) );
   226                     action->setObjectName( KRenamePlayList );
   230                     action->setObjectName( KRenamePlayList );
   242             default:
   246             default:
   243                 break;
   247                 break;
   244         }
   248         }
   245 
   249 
   246         if ( contextMenu ) {
   250         if ( contextMenu ) {
   247             mPermanentData->mContextMenuIndex = index;
   251             mPermanentData->mContextMenuModelIndex = index;
   248             contextMenu->setPreferredPos( coords );
   252             contextMenu->setPreferredPos( coords );
   249             contextMenu->setObjectName( KContextMenu );
   253             contextMenu->setObjectName( KContextMenu );
   250             contextMenu->setAttribute( Qt::WA_DeleteOnClose );
   254             contextMenu->setAttribute( Qt::WA_DeleteOnClose );
   251             setOutstandingPopup( contextMenu );
   255             setOutstandingPopup( contextMenu );
   252             contextMenu->open( this, SLOT( defaultContextMenuOptionSelected( HbAction* ) ) );
   256             contextMenu->open( this, SLOT( defaultContextMenuOptionSelected( HbAction* ) ) );
   257 }
   261 }
   258 
   262 
   259 /*!
   263 /*!
   260  Fetch view context menu
   264  Fetch view context menu
   261  */
   265  */
   262 void MpCollectionPopupHandler::openFetchViewContextMenu( int index, const QPointF &coords )
   266 void MpCollectionPopupHandler::openFetchViewContextMenu( const QModelIndex &index, const QPointF &coords )
   263 {
   267 {
   264     TX_ENTRY_ARGS( "index=" << index );
   268     TX_ENTRY_ARGS( "index=" << index.row() );
   265 
   269 
   266     if ( mView->isActivated() ) {
   270     if ( mView->isActivated() ) {
   267 
   271 
   268         HbAction *action;
   272         HbAction *action;
   269         HbMenu *contextMenu = 0;
   273         HbMenu *contextMenu = 0;
   281             default:
   285             default:
   282                 break;
   286                 break;
   283         }
   287         }
   284 
   288 
   285         if ( contextMenu ) {
   289         if ( contextMenu ) {
   286             mPermanentData->mContextMenuIndex = index;
   290             mPermanentData->mContextMenuModelIndex = index;
   287             contextMenu->setPreferredPos( coords );
   291             contextMenu->setPreferredPos( coords );
   288             contextMenu->setAttribute( Qt::WA_DeleteOnClose );
   292             contextMenu->setAttribute( Qt::WA_DeleteOnClose );
   289             contextMenu->setObjectName( KContextMenu );
   293             contextMenu->setObjectName( KContextMenu );
   290             setOutstandingPopup( contextMenu );
   294             setOutstandingPopup( contextMenu );
   291             contextMenu->open( this, SLOT( fetcherContextMenuOptionSelected( HbAction* ) ) );
   295             contextMenu->open( this, SLOT( fetcherContextMenuOptionSelected( HbAction* ) ) );
   300  */
   304  */
   301 void MpCollectionPopupHandler::openRenamePlaylistContainerDialog( const QString &currentName )
   305 void MpCollectionPopupHandler::openRenamePlaylistContainerDialog( const QString &currentName )
   302 {
   306 {
   303     TX_ENTRY_ARGS( "Current name=" << currentName );
   307     TX_ENTRY_ARGS( "Current name=" << currentName );
   304     mPermanentData->mOriginalName = currentName;
   308     mPermanentData->mOriginalName = currentName;
   305     getText( hbTrId( "txt_mus_dialog_enter_name" ), currentName,
   309     getText( hbTrId( "txt_mus_dialog_enter_name" ), 
       
   310              currentName,
       
   311              hbTrId( "txt_common_button_ok" ), //TODO:replace for "rename" when string is available
   306              SLOT( handleRenamePlaylistContainer( HbAction* ) ) );
   312              SLOT( handleRenamePlaylistContainer( HbAction* ) ) );
   307     TX_EXIT
   313     TX_EXIT
   308 }
   314 }
   309 
   315 
   310 /*!
   316 /*!
   312  */
   318  */
   313 void MpCollectionPopupHandler::openRenamePlaylistItemDialog( const QString &currentName )
   319 void MpCollectionPopupHandler::openRenamePlaylistItemDialog( const QString &currentName )
   314 {
   320 {
   315     TX_ENTRY_ARGS( "Current name=" << currentName );
   321     TX_ENTRY_ARGS( "Current name=" << currentName );
   316     mPermanentData->mOriginalName = currentName;
   322     mPermanentData->mOriginalName = currentName;
   317     getText( hbTrId( "txt_mus_dialog_enter_name" ), currentName,
   323     getText( hbTrId( "txt_mus_dialog_enter_name" ), 
       
   324              currentName,
       
   325              hbTrId( "txt_common_button_ok" ),//TODO:replace for "rename" when string is available
   318              SLOT( handleRenamePlaylistItem( HbAction* ) ) );
   326              SLOT( handleRenamePlaylistItem( HbAction* ) ) );
   319     TX_EXIT
   327     TX_EXIT
   320 }
   328 }
   321 
   329 
   322 /*!
   330 /*!
   323  Request to select songs to add to the playlist
   331  Request to select songs to add to the playlist
   324  */
   332  */
   325 void MpCollectionPopupHandler::openAddSongsToPlaylist( QAbstractItemModel* model )
   333 void MpCollectionPopupHandler::openAddSongsToPlaylist( QAbstractItemModel* model )
   326 {
   334 {
   327     TX_ENTRY
   335     TX_ENTRY
   328     getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), model,
   336     getModelIndexes( hbTrId( "txt_mus_title_select_songs" ),//TODO:replace for "add songs" when string is available
       
   337                      hbTrId( "txt_common_button_add_dialog" ),
       
   338                      model,
   329                      SLOT( handleAddSongsToPlayList( HbAction* ) ) );
   339                      SLOT( handleAddSongsToPlayList( HbAction* ) ) );
   330     TX_EXIT
   340     TX_EXIT
   331 }
   341 }
   332 
   342 
   333 /*!
   343 /*!
   339     MpCollectionTBoneListDataModel *model;
   349     MpCollectionTBoneListDataModel *model;
   340     model = new MpCollectionTBoneListDataModel( mMpEngine->collectionData() );
   350     model = new MpCollectionTBoneListDataModel( mMpEngine->collectionData() );
   341     //this item will be deleted when clearing permanent data.
   351     //this item will be deleted when clearing permanent data.
   342     model->setParent(mPermanentData);
   352     model->setParent(mPermanentData);
   343     model->refreshModel();
   353     model->refreshModel();
   344     getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), model,
   354     getModelIndexes( hbTrId( "txt_mus_title_select_songs" ),//TODO:replace for "add songs" when string is available
       
   355                      hbTrId( "txt_common_button_add_dialog" ),
       
   356                      model,
   345                      SLOT( handleAddSongsToPlayList( HbAction* ) ) );
   357                      SLOT( handleAddSongsToPlayList( HbAction* ) ) );
   346     TX_EXIT
   358     TX_EXIT
   347 }
   359 }
   348 
   360 
   349 /*!
   361 /*!
   350  Request to select songs to be deleted
   362  Request to select songs to be deleted
   351  */
   363  */
   352 void MpCollectionPopupHandler::openDeleteSongs( QAbstractItemModel* model )
   364 void MpCollectionPopupHandler::openDeleteSongs( QAbstractItemModel* model )
   353 {
   365 {
   354     TX_ENTRY
   366     TX_ENTRY
   355     getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), model, 
   367     //currently we can only get here from playlistsongs, no need to check for that.
       
   368     getModelIndexes( hbTrId( "txt_mus_title_remove_songs" ), 
       
   369                      hbTrId( "txt_common_button_remove_dialog" ),
       
   370                      model, 
   356                      SLOT( handleDeleteSongs( HbAction* ) ) );
   371                      SLOT( handleDeleteSongs( HbAction* ) ) );
   357     TX_EXIT
   372     TX_EXIT
   358 }
   373 }
   359 
   374 
   360 /*!
   375 /*!
   361  Request to select songs to be added to the current play list
   376  Request to select songs to be added to the current play list
   362  */
   377  */
   363 void MpCollectionPopupHandler::openAddToCurrentPlaylist( MpMpxCollectionData* collectionData )
   378 void MpCollectionPopupHandler::openAddToCurrentPlaylist( MpMpxCollectionData* collectionData )
   364 {
   379 {
   365     TX_ENTRY
   380     TX_ENTRY
   366     mPermanentData->mIsolatedCollectionData = collectionData;
   381     mPermanentData->mIsolatedOperation = true;
       
   382     mPermanentData->mCollectionData = collectionData;
   367     MpCollectionDataModel *collectionDataModel;
   383     MpCollectionDataModel *collectionDataModel;
   368     collectionDataModel = new MpCollectionDataModel( collectionData );
   384     collectionDataModel = new MpCollectionDataModel( collectionData );
       
   385     //this item will be deleted when clearing permanent data.
       
   386     collectionDataModel->setParent( mPermanentData );
   369     collectionDataModel->refreshModel();
   387     collectionDataModel->refreshModel();
   370     mPermanentData->mAbstractItemModel = collectionDataModel;
   388     mPermanentData->mAbstractItemModel = collectionDataModel;
   371 
   389 
   372     getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), collectionDataModel, 
   390     getModelIndexes( hbTrId( "txt_mus_title_select_songs" ),//TODO:replace for "add songs" when string is available
       
   391                      hbTrId( "txt_common_button_add_dialog" ),
       
   392                      collectionDataModel,
   373                      SLOT( handleAddToCurrentPlaylist( HbAction* ) ) );
   393                      SLOT( handleAddToCurrentPlaylist( HbAction* ) ) );
   374     TX_EXIT
   394     TX_EXIT
   375 }
   395 }
   376 
   396 
   377 /*!
   397 /*!
   378  Request to create a new play list and then add songs to it.
   398  Request to create a new play list and then add songs to it.
   379  */
   399  */
   380 void MpCollectionPopupHandler::openCreateNewPlaylist( MpMpxCollectionData* collectionData )
   400 void MpCollectionPopupHandler::openCreateNewPlaylist( MpMpxCollectionData* collectionData, bool isolated )
   381 {
   401 {
   382     TX_ENTRY
   402     TX_ENTRY
   383     mPermanentData->mIsolatedCollectionData = collectionData;
   403     mPermanentData->mIsolatedOperation = isolated;
   384 
   404     mPermanentData->mCollectionData = collectionData;
   385     MpCollectionDataModel *collectionDataModel;
   405     MpCollectionDataModel *collectionDataModel;
       
   406     //this item will be deleted when clearing permanent data.
   386     collectionDataModel = new MpCollectionDataModel( collectionData );
   407     collectionDataModel = new MpCollectionDataModel( collectionData );
       
   408     collectionDataModel->setParent( mPermanentData );
   387     collectionDataModel->refreshModel();
   409     collectionDataModel->refreshModel();
   388     mPermanentData->mAbstractItemModel = collectionDataModel;
   410     mPermanentData->mAbstractItemModel = collectionDataModel;
   389 
   411     QStringList playlists;
       
   412     mMpEngine->findPlaylists( playlists );
       
   413     queryNewPlaylistName( playlists, SLOT( handleCreateNewPlaylistGetTextFinished( HbAction* ) ) );
       
   414     TX_EXIT
       
   415 }
       
   416 
       
   417 /*!
       
   418  Request to create a new playlist from TBone
       
   419  */
       
   420 void MpCollectionPopupHandler::openCreateNewPlaylistFromTBone( )
       
   421 {
       
   422     TX_ENTRY
       
   423     mPermanentData->mIsolatedOperation = false;
       
   424     MpCollectionTBoneListDataModel *model;
       
   425     model = new MpCollectionTBoneListDataModel( mMpEngine->collectionData() );
       
   426     //this item will be deleted when clearing permanent data.
       
   427     model->setParent(mPermanentData);
       
   428     model->refreshModel();
       
   429     mPermanentData->mAbstractItemModel = model;
   390     QStringList playlists;
   430     QStringList playlists;
   391     mMpEngine->findPlaylists( playlists );
   431     mMpEngine->findPlaylists( playlists );
   392     queryNewPlaylistName( playlists, SLOT( handleCreateNewPlaylistGetTextFinished( HbAction* ) ) );
   432     queryNewPlaylistName( playlists, SLOT( handleCreateNewPlaylistGetTextFinished( HbAction* ) ) );
   393     TX_EXIT
   433     TX_EXIT
   394 }
   434 }
   416                 mPermanentData->clear();
   456                 mPermanentData->clear();
   417             }
   457             }
   418         }
   458         }
   419         else {
   459         else {
   420             mOutstandingPopup->close();
   460             mOutstandingPopup->close();
   421             //Delete/Clear permanent data until current popup gets deleted
   461             //Delete/Clear permanent data when current popup is deleted
   422             mPermanentData->setParent( mOutstandingPopup );
   462             mPermanentData->setParent( mOutstandingPopup );
   423             //Generate new permanent data for future popups
   463             //Generate new permanent data for future popups
   424             mPermanentData = new MpPopupHandlerPermanentData( this );
   464             mPermanentData = new MpPopupHandlerPermanentData( this );
   425         }
   465         }
   426     }
   466     }
   437 {
   477 {
   438     TX_ENTRY
   478     TX_ENTRY
   439     if ( selectedAction ) {
   479     if ( selectedAction ) {
   440         QString objectName = selectedAction->objectName();
   480         QString objectName = selectedAction->objectName();
   441         QList<int> selection;
   481         QList<int> selection;
   442         selection.append( mPermanentData->mContextMenuIndex );
   482         selection.append( mPermanentData->mContextMenuModelIndex.row() );
   443         if ( objectName == KOpen ) {
   483         if ( objectName == KOpen ) {
   444             mView->openItem( mPermanentData->mContextMenuIndex );
   484             mView->openItem( mPermanentData->mContextMenuModelIndex );
   445         }
   485         }
   446         if ( objectName == KAdd ) {
   486         if ( objectName == KAdd ) {
   447             launchAddToPlaylistDialog( selection );
   487             launchAddToPlaylistDialog( selection );
   448         }
   488         }
   449         else if ( objectName == KDelete ) {
   489         else if ( objectName == KDelete ) {
   450             requestDelete( selection );
   490             mPermanentData->mSelectedItems = selection;
       
   491             requestDelete();
   451         }
   492         }
   452         else if ( objectName == KRenamePlayList ) {
   493         else if ( objectName == KRenamePlayList ) {
   453             QString currentName;
   494             QString currentName;
   454             currentName = mMpEngine->collectionData()->itemData( 
   495             currentName = mMpEngine->collectionData()->itemData( 
   455                     mPermanentData->mContextMenuIndex, MpMpxCollectionData::Title );
   496                     mPermanentData->mContextMenuModelIndex.row(), MpMpxCollectionData::Title );
   456             openRenamePlaylistItemDialog( currentName );
   497             openRenamePlaylistItemDialog( currentName );
   457         }
   498         }
   458         else if ( objectName == KDetails ) {
   499         else if ( objectName == KDetails ) {
   459             mView->showItemDetails( mPermanentData->mContextMenuIndex );
   500             mView->showItemDetails( mPermanentData->mContextMenuModelIndex.row() );
   460         }
   501         }
   461     }
   502     }
   462     TX_EXIT
   503     TX_EXIT
   463 }
   504 }
   464 
   505 
   468 void MpCollectionPopupHandler::fetcherContextMenuOptionSelected( HbAction *selectedAction )
   509 void MpCollectionPopupHandler::fetcherContextMenuOptionSelected( HbAction *selectedAction )
   469 {
   510 {
   470     TX_ENTRY
   511     TX_ENTRY
   471     if ( selectedAction ) {
   512     if ( selectedAction ) {
   472         // Start the playback process. View will switch to playbackview.
   513         // Start the playback process. View will switch to playbackview.
   473         mMpEngine->previewItem( mPermanentData->mContextMenuIndex );
   514         mMpEngine->previewItem( mPermanentData->mContextMenuModelIndex.row() );
   474     }        
   515     }        
   475     TX_EXIT
   516     TX_EXIT
   476 }
   517 }
   477 
   518 
   478 /*!
   519 /*!
   517 
   558 
   518     if ( selectedAction ) {
   559     if ( selectedAction ) {
   519         QString objectName = selectedAction->objectName();
   560         QString objectName = selectedAction->objectName();
   520         if ( objectName == KOk ) {
   561         if ( objectName == KOk ) {
   521             QString newPlaylistName = dialog->value().toString();
   562             QString newPlaylistName = dialog->value().toString();
   522             if ( newPlaylistName.length() ) {
   563             //Create new playlist with given name
   523                 //Create new playlist with given name
   564             mMpEngine->createPlaylist( newPlaylistName, mPermanentData->mSelectedItems );
   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         }
   565         }
   533         else {
   566         else {
   534             // user decided to not provide a new name, go back to playlist list selection
   567             // user decided to not provide a new name, go back to playlist list selection
   535             QStringList playlists;
   568             QStringList playlists;
   536             mMpEngine->findPlaylists( playlists );
   569             mMpEngine->findPlaylists( playlists );
   554 void MpCollectionPopupHandler::handleRenamePlaylistContainer( HbAction *selectedAction )
   587 void MpCollectionPopupHandler::handleRenamePlaylistContainer( HbAction *selectedAction )
   555 {
   588 {
   556     TX_ENTRY
   589     TX_ENTRY
   557     HbInputDialog *dialog = qobject_cast<HbInputDialog *>( sender() );
   590     HbInputDialog *dialog = qobject_cast<HbInputDialog *>( sender() );
   558     clearOutstandingPopup( dialog );
   591     clearOutstandingPopup( dialog );
   559     bool operationCompleted( true );
       
   560 
   592 
   561     if ( selectedAction ) {
   593     if ( selectedAction ) {
   562         QString objectName = selectedAction->objectName();
   594         QString objectName = selectedAction->objectName();
   563         if ( objectName == KOk ) {
   595         if ( objectName == KOk ) {
   564             QString newPlaylistName = dialog->value().toString();
   596             QString newPlaylistName = dialog->value().toString();
   565             if ( newPlaylistName.length() ) {
   597             if ( newPlaylistName != mPermanentData->mOriginalName ) {
   566                 if ( newPlaylistName != mPermanentData->mOriginalName ) {
   598                 mMpEngine->renamePlaylist( newPlaylistName );
   567                     mMpEngine->renamePlaylist( newPlaylistName );
       
   568                 }
       
   569             }
   599             }
   570             else {
   600         }
   571                 //No valid name, prompt for one again.
   601     }
   572                 getText( hbTrId( "txt_mus_dialog_enter_name" ), newPlaylistName,
   602     mPermanentData->clear();
   573                          SLOT( handleRenamePlaylistContainer( HbAction* ) ) );
       
   574                 operationCompleted = false;
       
   575             }
       
   576         }
       
   577     }
       
   578 
       
   579     if ( operationCompleted ) {
       
   580         mPermanentData->clear();
       
   581     }
       
   582     TX_EXIT
   603     TX_EXIT
   583 }
   604 }
   584 
   605 
   585 /*!
   606 /*!
   586  Slot to be called when input dialog (getText) has finished, comming from RenamePlaylist ContextMenu.
   607  Slot to be called when input dialog (getText) has finished, comming from RenamePlaylist ContextMenu.
   588 void MpCollectionPopupHandler::handleRenamePlaylistItem( HbAction *selectedAction )
   609 void MpCollectionPopupHandler::handleRenamePlaylistItem( HbAction *selectedAction )
   589 {
   610 {
   590     TX_ENTRY
   611     TX_ENTRY
   591     HbInputDialog *dialog = qobject_cast<HbInputDialog *>( sender() );
   612     HbInputDialog *dialog = qobject_cast<HbInputDialog *>( sender() );
   592     clearOutstandingPopup( dialog );
   613     clearOutstandingPopup( dialog );
   593     bool operationCompleted( true );
       
   594 
   614 
   595     if ( selectedAction ) {
   615     if ( selectedAction ) {
   596         QString objectName = selectedAction->objectName();
   616         QString objectName = selectedAction->objectName();
   597         if ( objectName == KOk ) {
   617         if ( objectName == KOk ) {
   598             QString newPlaylistName = dialog->value().toString();
   618             QString newPlaylistName = dialog->value().toString();
   599             if ( newPlaylistName.length() ) {
   619             if ( newPlaylistName != mPermanentData->mOriginalName ) {
   600                 if ( newPlaylistName != mPermanentData->mOriginalName ) {
   620                 mMpEngine->renamePlaylist( newPlaylistName, mPermanentData->mContextMenuModelIndex.row() );
   601                     mMpEngine->renamePlaylist( newPlaylistName, mPermanentData->mContextMenuIndex );
       
   602                 }
   621                 }
   603             }
   622         }
   604             else {
   623     }
   605                 //No valid name, prompt for one again.
   624     mPermanentData->clear();
   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
   625     TX_EXIT
   617 }
   626 }
   618 
   627 
   619 /*!
   628 /*!
   620  Slot to be called when select songs dialog (getModelIndexes) has finished, coming from AddSongsToPlayList.
   629  Slot to be called when select songs dialog (getModelIndexes) has finished, coming from AddSongsToPlayList.
   637                 }
   646                 }
   638                 launchAddToPlaylistDialog( selection );
   647                 launchAddToPlaylistDialog( selection );
   639             }
   648             }
   640         }
   649         }
   641         else {
   650         else {
   642             mPermanentData->clear();
   651             //Delete/Clear permanent data when current dialog is deleted
       
   652             mPermanentData->setParent( dialog );
       
   653             //Generate new permanent data for future popups
       
   654             mPermanentData = new MpPopupHandlerPermanentData( this );
   643         }
   655         }
   644     }
   656     }
   645 
   657 
   646     //Dialog won't use CollectionView main model any more, return it to its original layout.
   658     //Dialog won't use CollectionView main model any more, return it to its original layout.
   647     MpCollectionDataModel *mpModel = qobject_cast<MpCollectionDataModel *>( dialog->model() );
   659     MpCollectionDataModel *mpModel = qobject_cast<MpCollectionDataModel *>( dialog->model() );
   661 {
   673 {
   662     TX_ENTRY
   674     TX_ENTRY
   663     HbSelectionDialog *dialog = qobject_cast<HbSelectionDialog *>( sender() );
   675     HbSelectionDialog *dialog = qobject_cast<HbSelectionDialog *>( sender() );
   664     clearOutstandingPopup( dialog );
   676     clearOutstandingPopup( dialog );
   665 
   677 
   666     if ( selectedAction ) {
   678     if ( selectedAction && selectedAction->objectName() == KOk ) {
   667         QString objectName = selectedAction->objectName();
   679         QModelIndexList selectedModelIndexes;
   668         if ( objectName == KOk ) {
   680         selectedModelIndexes = dialog->selectedModelIndexes();
   669             QModelIndexList selectedModelIndexes;
   681         if ( selectedModelIndexes.count() ) {
   670             selectedModelIndexes = dialog->selectedModelIndexes();
   682             QList<int> selection;
   671             if ( selectedModelIndexes.count() ) {
   683             for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
   672                 QList<int> selection;
   684                 selection.append( selectedModelIndexes.at( i ).row() );
   673                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
       
   674                     selection.append( selectedModelIndexes.at( i ).row() );
       
   675                 }
       
   676                 requestDelete( selection );
       
   677             }
   685             }
   678         }
   686             mPermanentData->mSelectedItems = selection;
   679     }
   687         }
   680 
   688         //we have to delay the delete, so the list on the dialog does not get the update (flicker!)
       
   689         connect( dialog, SIGNAL( destroyed() ), this, SLOT( requestDelete() ) );
       
   690     }
       
   691     else {
       
   692         mPermanentData->clear();
       
   693     }
   681     //Dialog won't use CollectionView main model any more, return it to its original layout.
   694     //Dialog won't use CollectionView main model any more, return it to its original layout.
   682     MpCollectionDataModel *mpModel = qobject_cast<MpCollectionDataModel *>( dialog->model() );
   695     MpCollectionDataModel *mpModel = qobject_cast<MpCollectionDataModel *>( dialog->model() );
   683     if ( mpModel ) {
   696     if ( mpModel ) {
   684         //setLayout() only applies for MpCollectionDataModel where we need to 
   697         //setLayout() only applies for MpCollectionDataModel where we need to 
   685         //decide which layout to use for the secondary text.
   698         //decide which layout to use for the secondary text.
   707                 QList<int> selection;
   720                 QList<int> selection;
   708                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
   721                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
   709                     selection.append( selectedModelIndexes.at( i ).row() );
   722                     selection.append( selectedModelIndexes.at( i ).row() );
   710                 }
   723                 }
   711                 mMpEngine->saveToCurrentPlaylist( selection,
   724                 mMpEngine->saveToCurrentPlaylist( selection,
   712                         mPermanentData->mIsolatedCollectionData );
   725                         mPermanentData->mCollectionData );
   713             }
   726             }
   714         }
   727         }
   715     }
   728     }
   716 
   729 
   717     //Dialog is using an isolated model which will be deleted, no need to change its layout.
   730     //Dialog is using an isolated model which will be deleted, no need to change its layout.
   718     mPermanentData->clear();
   731     
   719 
   732     //Delete/Clear permanent data when current dialog is deleted
       
   733     mPermanentData->setParent( dialog );
       
   734     //Generate new permanent data for future popups
       
   735     mPermanentData = new MpPopupHandlerPermanentData( this );
       
   736     
   720     TX_EXIT
   737     TX_EXIT
   721 }
   738 }
   722 
   739 
   723 /*!
   740 /*!
   724  Slot to be called when the input dialog (getText) has finished, comming from CreateNewPlaylist.
   741  Slot to be called when the input dialog (getText) has finished, comming from CreateNewPlaylist.
   726 void MpCollectionPopupHandler::handleCreateNewPlaylistGetTextFinished( HbAction *selectedAction )
   743 void MpCollectionPopupHandler::handleCreateNewPlaylistGetTextFinished( HbAction *selectedAction )
   727 {
   744 {
   728     TX_ENTRY
   745     TX_ENTRY
   729     HbInputDialog *dialog = qobject_cast<HbInputDialog *>( sender() );
   746     HbInputDialog *dialog = qobject_cast<HbInputDialog *>( sender() );
   730     clearOutstandingPopup( dialog );
   747     clearOutstandingPopup( dialog );
   731     bool operationCompleted( true );
   748 
   732 
   749     if ( selectedAction && selectedAction->objectName() == KOk) {
   733     if ( selectedAction ) {
   750         QString newPlaylistName = dialog->value().toString();
   734         QString objectName = selectedAction->objectName();
   751         //Store the new playlist name and query for the items to be added
   735         if ( objectName == KOk ) {
   752         mPermanentData->mOriginalName = newPlaylistName;
   736             QString newPlaylistName = dialog->value().toString();
   753         getModelIndexes( hbTrId( "txt_mus_title_select_songs" ),//TODO:replace for "add songs" when string is available
   737             if ( newPlaylistName.length() ) {
   754                          hbTrId( "txt_common_button_add_dialog" ),
   738                 //Store the new playlist name and query for the items to be added
   755                          mPermanentData->mAbstractItemModel, 
   739                 mPermanentData->mOriginalName = newPlaylistName;
   756                          SLOT( handleCreateNewPlaylistGetModelIndexesFinished( HbAction* ) ) );
   740                 getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), 
   757     }
   741                                  mPermanentData->mAbstractItemModel, 
   758     else {
   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();
   759         mPermanentData->clear();
   755     }
   760     }
   756     TX_EXIT
   761     TX_EXIT
   757 }
   762 }
   758 
   763 
   773             selectedModelIndexes = dialog->selectedModelIndexes();
   778             selectedModelIndexes = dialog->selectedModelIndexes();
   774             if ( selectedModelIndexes.count() ) {
   779             if ( selectedModelIndexes.count() ) {
   775                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
   780                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
   776                     selection.append( selectedModelIndexes.at( i ).row() );
   781                     selection.append( selectedModelIndexes.at( i ).row() );
   777                 }
   782                 }
       
   783                 mMpEngine->createPlaylist( mPermanentData->mOriginalName, selection,
       
   784                         mPermanentData->mCollectionData );
   778             }
   785             }
   779             //Creating Playlist even when there is no selection.
   786         }
   780             mMpEngine->createPlaylist( mPermanentData->mOriginalName, selection,
   787     }
   781                     mPermanentData->mIsolatedCollectionData );
   788 
   782         }
   789     
   783     }
   790     //Delete/Clear permanent data when current dialog is deleted
   784 
   791     mPermanentData->setParent( dialog );
   785     //Dialog is using an isolated model which will be deleted, no need to change its layout.
   792     //Generate new permanent data for future popups
   786     mPermanentData->clear();
   793     mPermanentData = new MpPopupHandlerPermanentData( this );
   787 
   794 
       
   795 
       
   796     //Dialog won't use model any more, return it to its original layout.
       
   797     MpCollectionDataModel *mpModel = qobject_cast<MpCollectionDataModel *>( dialog->model() );
       
   798     if ( mpModel ) {
       
   799         //setLayout() only applies for MpCollectionDataModel where we need to 
       
   800         //decide which layout to use for the secondary text.
       
   801         //MpCollectionTBoneListDataModel doesn't have secondary text.
       
   802         mpModel->setLayout( ECollectionListView );
       
   803     }
   788     TX_EXIT
   804     TX_EXIT
   789 }
   805 }
   790 
   806 
   791 /*!
   807 /*!
   792  Slot to be called when arrange songs dialog has finished.
   808  Slot to be called when arrange songs dialog has finished.
   894     }
   910     }
   895     TX_EXIT
   911     TX_EXIT
   896 }
   912 }
   897 
   913 
   898 /*!
   914 /*!
       
   915  Slot to be called when the text on an input dialog changes.
       
   916  */
       
   917 void MpCollectionPopupHandler::inputDialogChanged( QString text )
       
   918 {
       
   919     if ( !mOutstandingPopup ) {
       
   920         return;
       
   921     }
       
   922     //Attempt to cast the outstanding dialog as the input dialog that owns the 
       
   923     //line edit that changed. If cast fails it means that the dialog is out of
       
   924     //scope and the operation is not needed anymore.
       
   925     HbInputDialog *dialog = qobject_cast<HbInputDialog *>( mOutstandingPopup );
       
   926     HbLineEdit *dialogLineEdit = qobject_cast<HbLineEdit *>( sender() );
       
   927     if ( dialog && dialogLineEdit && dialog->lineEdit() == dialogLineEdit ) {
       
   928         if ( dialog->actions().count() ) {
       
   929             dialog->actions()[0]->setEnabled( !text.isEmpty() );
       
   930         }
       
   931     }
       
   932 }
       
   933 
       
   934 /*!
   899  \internal
   935  \internal
   900  sets \a popup as the current outstanding popup and cancels any other previous popup.
   936  Slot to be called to request a delete operation upon user confirmation.
   901  */
   937  */
   902 void MpCollectionPopupHandler::setOutstandingPopup( HbPopup *popup )
   938 void MpCollectionPopupHandler::requestDelete()
   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 {
   939 {
  1113     TX_ENTRY
   940     TX_ENTRY
  1114     QString message;
   941     QString message;
  1115     mPermanentData->mSelectedItems = selection;
       
  1116     bool needsConfirmation = true;
   942     bool needsConfirmation = true;
  1117     connectExternalEvents();
   943     connectExternalEvents();
  1118 
   944 
  1119     switch ( mMpEngine->collectionData()->context() ) {
   945     switch ( mMpEngine->collectionData()->context() ) {
  1120         case ECollectionContextAllSongs:
   946         case ECollectionContextAllSongs:
  1169     TX_EXIT
   995     TX_EXIT
  1170 }
   996 }
  1171 
   997 
  1172 /*!
   998 /*!
  1173  \internal
   999  \internal
       
  1000  sets \a popup as the current outstanding popup and cancels any other previous popup.
       
  1001  */
       
  1002 void MpCollectionPopupHandler::setOutstandingPopup( HbPopup *popup )
       
  1003 {
       
  1004     TX_ENTRY
       
  1005     if ( mOutstandingPopup ) {
       
  1006         TX_LOG_ARGS( "Warning: Multiple popups attempted to be displayed" );
       
  1007         mOutstandingPopup->close();
       
  1008     }
       
  1009 
       
  1010     connect( popup, SIGNAL( aboutToClose() ), this, SLOT( outstandingPopupClosing() ) );
       
  1011     mOutstandingPopup = popup;
       
  1012     TX_EXIT
       
  1013 }
       
  1014 
       
  1015 /*!
       
  1016  \internal
       
  1017  clears and disconnects \a popup. In some cases it's needed to open a new dialog when a current one has just finished.
       
  1018  */
       
  1019 void MpCollectionPopupHandler::clearOutstandingPopup( HbPopup *popup )
       
  1020 {
       
  1021     TX_ENTRY
       
  1022     disconnect( popup, SIGNAL( aboutToClose() ), this, SLOT( outstandingPopupClosing() ) );
       
  1023     mOutstandingPopup = 0;
       
  1024     TX_EXIT
       
  1025 }
       
  1026 
       
  1027 /*!
       
  1028  \internal
       
  1029  Launches the 'Add to playlist' dialog.
       
  1030  */
       
  1031 void MpCollectionPopupHandler::launchAddToPlaylistDialog( QList<int> &selection )
       
  1032 {
       
  1033     TX_ENTRY
       
  1034 
       
  1035     QStringList playlists;
       
  1036     mPermanentData->mSelectedItems = selection;
       
  1037     mMpEngine->findPlaylists( playlists );
       
  1038     if ( playlists.count() ) {
       
  1039         //There are saved playlists, query for a saved playlist or new.
       
  1040         HbAction *action;
       
  1041         HbSelectionDialog *dialog = new HbSelectionDialog();
       
  1042         dialog->setStringItems( playlists );
       
  1043         dialog->setSelectionMode( HbAbstractItemView::SingleSelection );
       
  1044         dialog->setSelectedItems( QList< QVariant >());
       
  1045         dialog->setHeadingWidget(new HbLabel( hbTrId( "txt_mus_title_select_playlist" ) ) );
       
  1046         dialog->clearActions();
       
  1047         action = new HbAction( hbTrId( "txt_mus_button_new" ) );
       
  1048         action->setObjectName( KNew );
       
  1049         dialog->addAction( action );
       
  1050         action = new HbAction( hbTrId( "txt_common_button_cancel" ) );
       
  1051         action->setObjectName( KCancel );
       
  1052         dialog->addAction( action );
       
  1053         dialog->setObjectName( KAddToPlaylistSelectionDialog );
       
  1054         dialog->setAttribute( Qt::WA_DeleteOnClose );
       
  1055         setOutstandingPopup( dialog );
       
  1056         dialog->open( this, SLOT( handleAddToPlaylistDialogFinished( HbAction* ) ) );
       
  1057     }
       
  1058     else {
       
  1059         //querying for a new playlist name.
       
  1060         queryNewPlaylistName( playlists, SLOT( handleAddToPlaylistGetTextFinished( HbAction* ) ) );
       
  1061     }
       
  1062     TX_EXIT
       
  1063 }
       
  1064 
       
  1065 /*!
       
  1066  \internal
       
  1067  Trigger an imput text dialog with a suggested playlist name.
       
  1068  uses \a playlists to generate a suggested playlist name
       
  1069  \handler Slot that should be called when input dialog finished 
       
  1070  */
       
  1071 void MpCollectionPopupHandler::queryNewPlaylistName(const QStringList &playlists,
       
  1072                                                     const char *handler ) 
       
  1073 {
       
  1074     TX_ENTRY
       
  1075     int i = 0;
       
  1076     for ( ;
       
  1077          playlists.contains( hbTrId( "txt_mus_dialog_enter_name_entry_playlist_l1" ).arg( i ) ) ;
       
  1078          i++ ) {};
       
  1079     QString suggestedPlaylistName = hbTrId( "txt_mus_dialog_enter_name_entry_playlist_l1" ).arg( i );
       
  1080     getText( hbTrId( "txt_mus_dialog_enter_name" ), 
       
  1081              suggestedPlaylistName, 
       
  1082              hbTrId( "txt_mus_button_create_new" ),
       
  1083              handler );
       
  1084     TX_EXIT
       
  1085 }
       
  1086 
       
  1087 /*!
       
  1088  \internal
       
  1089  Launches an input text dialog.
       
  1090  \a label Dialog title.
       
  1091  \a text Suggested text.
       
  1092  \a confirmationActionLabel label for the first action on the dialog.
       
  1093  \a handler Slot to be called when input dialog finishes.
       
  1094  */
       
  1095 void MpCollectionPopupHandler::getText( const QString &label, 
       
  1096                                         const QString &text,
       
  1097                                         const QString &confirmationActionLabel,
       
  1098                                         const char *handler )
       
  1099 {
       
  1100     TX_ENTRY
       
  1101     HbAction *action;
       
  1102     HbInputDialog *dialog = new HbInputDialog();
       
  1103     dialog->setPromptText( label );
       
  1104     dialog->setInputMode( HbInputDialog::TextInput );
       
  1105     dialog->setValue( text );
       
  1106     dialog->clearActions();
       
  1107     action = new HbAction( confirmationActionLabel );
       
  1108     action->setObjectName( KOk );
       
  1109     dialog->addAction( action );
       
  1110     
       
  1111     //we want to prevent the user from slecting an empty string.
       
  1112     HbLineEdit  * lineEdit;
       
  1113     lineEdit = dialog->lineEdit();
       
  1114     connect (lineEdit , SIGNAL(textChanged(QString)), SLOT(inputDialogChanged(QString)) );
       
  1115     action->setEnabled( !lineEdit->text().isEmpty() );
       
  1116     
       
  1117     action = new HbAction( hbTrId( "txt_common_button_cancel" ) );
       
  1118     action->setObjectName( KCancel );
       
  1119     dialog->addAction( action );
       
  1120     dialog->setObjectName( KInputTextDialog );
       
  1121     dialog->setAttribute( Qt::WA_DeleteOnClose );
       
  1122     setOutstandingPopup( dialog );
       
  1123     dialog->open( this, handler );
       
  1124     TX_EXIT
       
  1125 }
       
  1126 
       
  1127 /*!
       
  1128  \internal
       
  1129  Launches a list dialog to select items.
       
  1130  \a label Dialog title.
       
  1131  \a confirmationActionLabel label for the first action on the dialog.
       
  1132  \a model List model.
       
  1133  \a handler Slot to be called when list dialog finishes.
       
  1134  */
       
  1135 void MpCollectionPopupHandler::getModelIndexes( const QString &label, 
       
  1136                                                 const QString &confirmationActionLabel,
       
  1137                                                 QAbstractItemModel* model,
       
  1138                                                 const char *handler)
       
  1139 {   
       
  1140     TX_ENTRY
       
  1141 
       
  1142     connectExternalEvents();
       
  1143 
       
  1144     HbAction *action;
       
  1145     HbSelectionDialog *dialog = new HbSelectionDialog();
       
  1146     dialog->setHeadingWidget( new HbLabel( label ) );
       
  1147     dialog->setSelectionMode( HbAbstractItemView::MultiSelection );
       
  1148     MpCollectionDataModel *mpModel = qobject_cast<MpCollectionDataModel *>( model );
       
  1149     if ( mpModel ) {
       
  1150         //setLayout() only applies for MpCollectionDataModel where we need to 
       
  1151         //decide which layout to use for the secondary text.
       
  1152         //MpCollectionTBoneListDataModel doesn't have secondary text.
       
  1153         mpModel->setLayout( ECollectionSelectionDialog );
       
  1154     }
       
  1155     dialog->setModel( model );
       
  1156     dialog->clearActions();
       
  1157     action = new HbAction( confirmationActionLabel );
       
  1158     action->setObjectName( KOk );
       
  1159     dialog->addAction( action );
       
  1160     action = new HbAction( hbTrId( "txt_common_button_cancel" ) );
       
  1161     action->setObjectName( KCancel );
       
  1162     dialog->addAction( action );
       
  1163     dialog->setObjectName( KGetModelIndexesListDialog );
       
  1164     dialog->setAttribute( Qt::WA_DeleteOnClose );
       
  1165     setOutstandingPopup( dialog );
       
  1166     dialog->open( this, handler );
       
  1167 
       
  1168     TX_EXIT
       
  1169 }
       
  1170 
       
  1171 /*!
       
  1172  \internal
       
  1173  Launches a list dialog to reorder them.
       
  1174  */
       
  1175 void MpCollectionPopupHandler::launchArrangeSongsDialog()
       
  1176 {   
       
  1177     TX_ENTRY
       
  1178 
       
  1179     HbListView *listView = new HbListView();
       
  1180     listView->setItemRecycling( true );
       
  1181     listView->setScrollingStyle( HbListView::PanOrFlick );
       
  1182     listView->setClampingStyle( HbListView::BounceBackClamping );
       
  1183     HbScrollBar *scrollbar = listView->verticalScrollBar();
       
  1184     scrollbar->show();
       
  1185     scrollbar->setInteractive( true);
       
  1186     listView->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded);
       
  1187     MpCollectionDataModel *model;
       
  1188     //Ownership of the model is passed to the listView as a child object.
       
  1189     model = new MpCollectionDataModel( mMpEngine->collectionData() , mMpEngine->playbackData(), listView );
       
  1190     model->refreshModel();
       
  1191     connect( model,
       
  1192              SIGNAL( orderChanged( int, int, int, int ) ),
       
  1193              mMpEngine,
       
  1194              SLOT( reorderPlaylist( int, int, int, int ) ) );
       
  1195     MpCollectionDataModel *mpModel = qobject_cast<MpCollectionDataModel *>( model );
       
  1196     if ( mpModel ) {
       
  1197         //setLayout() only applies for MpCollectionDataModel where we need to 
       
  1198         //decide which layout to use for the secondary text.
       
  1199         //MpCollectionTBoneListDataModel doesn't have secondary text.
       
  1200         mpModel->setLayout( ECollectionArrangeSongsDialog );
       
  1201     }
       
  1202     listView->setModel( model );
       
  1203     listView->setArrangeMode( true );
       
  1204     HbDialog *dialog = new HbDialog();
       
  1205     dialog->setDismissPolicy( HbPopup::NoDismiss );
       
  1206     dialog->setTimeout( HbPopup::NoTimeout );
       
  1207 
       
  1208     HbLabel *label = new HbLabel( hbTrId( "txt_mus_title_arrange"  ) );
       
  1209     dialog->setHeadingWidget( label );
       
  1210     dialog->setContentWidget( listView );
       
  1211     dialog->clearActions();
       
  1212     HbAction *action;
       
  1213     action = new HbAction( hbTrId( "txt_common_button_ok" ) );
       
  1214     dialog->addAction( action );
       
  1215     dialog->setObjectName( KArrangeSongsDialog );
       
  1216     dialog->setAttribute( Qt::WA_DeleteOnClose );
       
  1217     setOutstandingPopup(dialog);
       
  1218     dialog->open( this, SLOT( handleArrangeSongs( HbAction* ) ) );
       
  1219 
       
  1220     TX_EXIT
       
  1221 }
       
  1222 
       
  1223 /*!
       
  1224  \internal
  1174  Launches a waiting progress note.
  1225  Launches a waiting progress note.
  1175  \a content String id to display in the dialog.
  1226  \a content String id to display in the dialog.
  1176  */
  1227  */
  1177 void MpCollectionPopupHandler::launchProgressDialog( const char *id )
  1228 void MpCollectionPopupHandler::launchProgressDialog( const char *id )
  1178 {
  1229 {