mpviewplugins/mpcollectionviewplugin/src/mpcollectionpopuphandler.cpp
branchGCC_SURGE
changeset 44 eff9df3d9c98
parent 41 ea59c434026a
child 43 0f32e550d9d8
equal deleted inserted replaced
30:b95ddb5a0d10 44:eff9df3d9c98
    17 
    17 
    18 // INCLUDE FILES
    18 // INCLUDE FILES
    19 #include <hbaction.h>
    19 #include <hbaction.h>
    20 #include <hbmenu.h>
    20 #include <hbmenu.h>
    21 #include <hbmessagebox.h>
    21 #include <hbmessagebox.h>
       
    22 #include <hbprogressdialog.h>
    22 #include <hbselectiondialog.h>
    23 #include <hbselectiondialog.h>
    23 #include <hbinputdialog.h>
    24 #include <hbinputdialog.h>
    24 #include <hblabel.h>
    25 #include <hblabel.h>
    25 #include <hblistview.h>
    26 #include <hblistview.h>
    26 #include <hbscrollbar.h>
    27 #include <hbscrollbar.h>
    27 
    28 
    28 #include "mpengine.h"
    29 #include "mpenginefactory.h"
    29 #include "mpcollectionview.h"
    30 #include "mpcollectionview.h"
    30 #include "mpmpxcollectiondata.h"
    31 #include "mpmpxcollectiondata.h"
    31 #include "mpcollectiondatamodel.h"
    32 #include "mpcollectiondatamodel.h"
    32 #include "mpmpxcollectionviewdefs.h"
    33 #include "mpcollectiontbonelistdatamodel.h"
    33 #include "mpcollectionpopuphandler.h"
    34 #include "mpcollectionpopuphandler.h"
    34 #include "mptrace.h"
    35 #include "mptrace.h"
    35 
    36 
    36 const int KNullIndex = -1;
    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 
       
    58 
       
    59 //------------------------------------------------------------------
       
    60 //    MpPopupHandlerPermanentData
       
    61 //------------------------------------------------------------------
       
    62 
       
    63 /*!
       
    64     \class MpPopupHandlerPermanentData. This class is used by MpCollectionPopupHandler to
       
    65     store permanent data needed during asynchronous popups operation.
       
    66 
       
    67 */
       
    68 
       
    69 class MpPopupHandlerPermanentData : public QObject
       
    70 {
       
    71     public:
       
    72         MpPopupHandlerPermanentData( QObject *parent=0 );
       
    73         virtual ~MpPopupHandlerPermanentData();
       
    74         void clear();
       
    75     public:
       
    76         MpMpxCollectionData         *mIsolatedCollectionData;        // Not own
       
    77         QAbstractItemModel          *mAbstractItemModel;             // Own
       
    78         QList<int>                  mSelectedItems;
       
    79         QString                     mOriginalName;
       
    80         int                         mContextMenuIndex;
       
    81 };
       
    82 
       
    83 /*!
       
    84  Constructs the popup handler permanent data.
       
    85  */
       
    86 MpPopupHandlerPermanentData::MpPopupHandlerPermanentData( QObject *parent )
       
    87     : QObject( parent ),
       
    88       mIsolatedCollectionData( 0 ),
       
    89       mAbstractItemModel( 0 ),
       
    90       mContextMenuIndex( KNullIndex )
       
    91 {
       
    92       TX_ENTRY
       
    93       mSelectedItems.clear();
       
    94       mOriginalName.clear();
       
    95       TX_EXIT
       
    96 }
       
    97 
       
    98 /*!
       
    99  Destructs the popup handler permanent data.
       
   100  */
       
   101 MpPopupHandlerPermanentData::~MpPopupHandlerPermanentData()
       
   102 {
       
   103     TX_ENTRY
       
   104     clear();
       
   105     TX_EXIT
       
   106 }
       
   107 
       
   108 /*!
       
   109  \internal
       
   110   Clears all permanent data. 
       
   111  */
       
   112 void MpPopupHandlerPermanentData::clear()
       
   113 {
       
   114     TX_ENTRY
       
   115     mSelectedItems.clear();
       
   116     mOriginalName.clear();
       
   117     mContextMenuIndex = KNullIndex;
       
   118     if ( mIsolatedCollectionData ) {
       
   119         MpEngineFactory::sharedEngine()->releaseIsolatedCollection();
       
   120         mIsolatedCollectionData = 0;
       
   121     }
       
   122     if ( mAbstractItemModel ) {
       
   123         delete mAbstractItemModel;
       
   124         mAbstractItemModel = 0;
       
   125     }
       
   126     //clearing any child Objects.
       
   127     foreach (QObject* child, children()) {
       
   128         child->deleteLater();
       
   129     }
       
   130     TX_EXIT
       
   131 }
       
   132 
       
   133 
       
   134 //------------------------------------------------------------------
       
   135 //    MpCollectionPopupHandler
       
   136 //------------------------------------------------------------------
    37 
   137 
    38 /*!
   138 /*!
    39     \class MpCollectionPopupHandler
   139     \class MpCollectionPopupHandler
    40     \brief Music Player collection popup handler.
   140     \brief Music Player collection popup handler.
    41 
   141 
    49 MpCollectionPopupHandler::MpCollectionPopupHandler( MpCollectionView *parent )
   149 MpCollectionPopupHandler::MpCollectionPopupHandler( MpCollectionView *parent )
    50     : QObject( parent ),
   150     : QObject( parent ),
    51       mView( parent ),
   151       mView( parent ),
    52       mOutstandingPopup( 0 ),
   152       mOutstandingPopup( 0 ),
    53       mMpEngine( 0 ),
   153       mMpEngine( 0 ),
    54       mPermanentData( 0 )
   154       mPermanentData( 0 ),
    55 {
   155       mExternalEventsConnected( false )
    56     TX_ENTRY
   156 {
    57     mMpEngine = MpEngine::instance();
   157     TX_ENTRY
       
   158     mMpEngine = MpEngineFactory::sharedEngine();
    58     mPermanentData = new MpPopupHandlerPermanentData( this );
   159     mPermanentData = new MpPopupHandlerPermanentData( this );
    59     TX_EXIT
   160     TX_EXIT
    60 }
   161 }
    61 
   162 
    62 /*!
   163 /*!
    73  Default view context menu.
   174  Default view context menu.
    74  */
   175  */
    75 void MpCollectionPopupHandler::openDefaultViewContextMenu( int index, const QPointF &coords )
   176 void MpCollectionPopupHandler::openDefaultViewContextMenu( int index, const QPointF &coords )
    76 {
   177 {
    77     TX_ENTRY
   178     TX_ENTRY
    78     HbMenu *contextMenu = 0;
   179 
    79     HbAction *action;
   180     if ( mView->isActivated() ) {
    80     bool usbBlocked = mMpEngine->verifyUsbBlocking();
   181 
    81 
   182         HbMenu *contextMenu = 0;
    82     switch ( mMpEngine->collectionData()->context() ) {
   183         HbAction *action;
    83         case ECollectionContextAllSongs:
   184         bool usbBlocked = mMpEngine->verifyUsbBlocking();
    84         case ECollectionContextArtistSongs:
   185 
    85         case ECollectionContextAlbumSongs:
   186         switch ( mMpEngine->collectionData()->context() ) {
    86             contextMenu = new HbMenu();
   187             case ECollectionContextAllSongs:
    87             action = contextMenu->addAction( hbTrId( "txt_common_menu_play_music" ) );
   188             case ECollectionContextArtistAllSongs:
    88             action->setObjectName( "open" );
   189             case ECollectionContextArtistAlbumsTBone:
    89             action = contextMenu->addAction( hbTrId( "txt_mus_menu_add_to_playlist" ) );
   190             case ECollectionContextAlbumsTBone:
    90             action->setObjectName( "add" );
   191                 contextMenu = new HbMenu();
    91             action->setEnabled( !usbBlocked );
   192                 action = contextMenu->addAction( hbTrId( "txt_common_menu_play_music" ) );
    92             action = contextMenu->addAction( hbTrId( "txt_common_menu_delete" ) );
   193                 action->setObjectName( KOpen );
    93             action->setObjectName( "delete" );
   194                 action = contextMenu->addAction( hbTrId( "txt_mus_menu_add_to_playlist" ) );
    94             action->setEnabled( !usbBlocked );
   195                 action->setObjectName( KAdd );
    95             break;
   196                 action->setEnabled( !usbBlocked );
    96         case ECollectionContextAlbums:
   197                 action = contextMenu->addAction( hbTrId( "txt_common_menu_delete" ) );
    97         case ECollectionContextArtists:
   198                 action->setObjectName( KDelete );
    98         case ECollectionContextArtistAlbums:
   199                 action->setEnabled( !usbBlocked );
    99             contextMenu = new HbMenu();
   200                 break;
   100             action = contextMenu->addAction( hbTrId( "txt_common_menu_open" ) );
   201             case ECollectionContextAlbums:
   101             action->setObjectName( "open" );
   202             case ECollectionContextArtists:
   102             action = contextMenu->addAction( hbTrId( "txt_mus_menu_add_to_playlist" ) );
   203             case ECollectionContextArtistAlbums:
   103             action->setObjectName( "add" );
       
   104             action->setEnabled( !usbBlocked );
       
   105             action = contextMenu->addAction( hbTrId( "txt_common_menu_delete" ) );
       
   106             action->setObjectName( "delete" );
       
   107             action->setEnabled( !usbBlocked );
       
   108             break;
       
   109         case ECollectionContextPlaylists:
       
   110             if ( !mMpEngine->collectionData()->isAutoPlaylist( index ) ) {
       
   111                 contextMenu = new HbMenu();
   204                 contextMenu = new HbMenu();
   112                 action = contextMenu->addAction( hbTrId( "txt_common_menu_open" ) );
   205                 action = contextMenu->addAction( hbTrId( "txt_common_menu_open" ) );
   113                 action->setObjectName( "open" );
   206                 action->setObjectName( KOpen );
       
   207                 action = contextMenu->addAction( hbTrId( "txt_mus_menu_add_to_playlist" ) );
       
   208                 action->setObjectName( KAdd );
       
   209                 action->setEnabled( !usbBlocked );
   114                 action = contextMenu->addAction( hbTrId( "txt_common_menu_delete" ) );
   210                 action = contextMenu->addAction( hbTrId( "txt_common_menu_delete" ) );
   115                 action->setObjectName("delete");
   211                 action->setObjectName( KDelete );
   116                 action->setEnabled( !usbBlocked );
   212                 action->setEnabled( !usbBlocked );
   117                 action = contextMenu->addAction( hbTrId( "txt_common_menu_rename_item" ) );
   213                 break;
   118                 action->setObjectName( "rename playlist" );
   214             case ECollectionContextPlaylists:
   119                 action->setEnabled( !usbBlocked );
   215                 if ( !mMpEngine->collectionData()->isAutoPlaylist( index ) ) {
   120             }
   216                     contextMenu = new HbMenu();
   121             break;
   217                     action = contextMenu->addAction( hbTrId( "txt_common_menu_open" ) );
   122         case ECollectionContextPlaylistSongs:
   218                     action->setObjectName( KOpen );
   123             if ( !mMpEngine->collectionData()->isAutoPlaylist() ) {
   219                     action = contextMenu->addAction( hbTrId( "txt_common_menu_delete" ) );
       
   220                     action->setObjectName(KDelete);
       
   221                     action->setEnabled( !usbBlocked );
       
   222                     action = contextMenu->addAction( hbTrId( "txt_common_menu_rename_item" ) );
       
   223                     action->setObjectName( KRenamePlayList );
       
   224                     action->setEnabled( !usbBlocked );
       
   225                 }
       
   226                 break;
       
   227             case ECollectionContextPlaylistSongs:
       
   228                 if ( !mMpEngine->collectionData()->isAutoPlaylist() ) {
       
   229                     contextMenu = new HbMenu();
       
   230                     action = contextMenu->addAction( hbTrId( "txt_common_menu_play_music" ) );
       
   231                     action->setObjectName( KOpen );
       
   232                     action = contextMenu->addAction( hbTrId( "txt_common_menu_remove" ) );
       
   233                     action->setObjectName( KDelete );
       
   234                     action->setEnabled( !usbBlocked );
       
   235                 }
       
   236                 break;
       
   237             default:
       
   238                 break;
       
   239         }
       
   240 
       
   241         if ( contextMenu ) {
       
   242             mPermanentData->mContextMenuIndex = index;
       
   243             contextMenu->setPreferredPos( coords );
       
   244             contextMenu->setObjectName( KContextMenu );
       
   245             contextMenu->setAttribute( Qt::WA_DeleteOnClose );
       
   246             setOutstandingPopup( contextMenu );
       
   247             contextMenu->open( this, SLOT( defaultContextMenuOptionSelected( HbAction* ) ) );
       
   248         }
       
   249     }
       
   250 
       
   251     TX_EXIT
       
   252 }
       
   253 
       
   254 /*!
       
   255  Fetch view context menu
       
   256  */
       
   257 void MpCollectionPopupHandler::openFetchViewContextMenu( int index, const QPointF &coords )
       
   258 {
       
   259     TX_ENTRY_ARGS( "index=" << index );
       
   260 
       
   261     if ( mView->isActivated() ) {
       
   262 
       
   263         HbAction *action;
       
   264         HbMenu *contextMenu = 0;
       
   265 
       
   266         switch ( mMpEngine->collectionData()->context() ) {
       
   267             case ECollectionContextAllSongs:
       
   268             case ECollectionContextArtistAlbumsTBone:
       
   269             case ECollectionContextArtistAllSongs:
       
   270             case ECollectionContextAlbumsTBone:
       
   271             case ECollectionContextPlaylistSongs:
   124                 contextMenu = new HbMenu();
   272                 contextMenu = new HbMenu();
   125                 action = contextMenu->addAction( hbTrId( "txt_common_menu_play_music" ) );
   273                 action = contextMenu->addAction( hbTrId("txt_common_menu_play_music") );
   126                 action->setObjectName( "open" );
   274                 action->setEnabled( !mMpEngine->verifyUsbBlocking() );
   127                 action = contextMenu->addAction( hbTrId( "txt_common_menu_remove" ) );
   275                 break;
   128                 action->setObjectName( "delete" );
   276             default:
   129                 action->setEnabled( !usbBlocked );
   277                 break;
   130             }
   278         }
   131             break;
   279 
   132         default:
   280         if ( contextMenu ) {
   133             break;
       
   134     }
       
   135 
       
   136     if ( contextMenu ) {
       
   137         if ( mView->isActivated() ) {
       
   138             mPermanentData->mContextMenuIndex = index;
   281             mPermanentData->mContextMenuIndex = index;
   139             contextMenu->setPreferredPos( coords );
   282             contextMenu->setPreferredPos( coords );
   140             contextMenu->setAttribute( Qt::WA_DeleteOnClose );
   283             contextMenu->setAttribute( Qt::WA_DeleteOnClose );
       
   284             contextMenu->setObjectName( KContextMenu );
   141             setOutstandingPopup( contextMenu );
   285             setOutstandingPopup( contextMenu );
   142             contextMenu->open( this, SLOT( defaultContextMenuOptionSelected( HbAction* ) ) );
   286             contextMenu->open( this, SLOT( fetcherContextMenuOptionSelected( HbAction* ) ) );
   143         }
       
   144         else {
       
   145             delete contextMenu;
       
   146             contextMenu = 0;
       
   147         }
       
   148     }
       
   149 
       
   150     TX_EXIT
       
   151 }
       
   152 
       
   153 /*!
       
   154  Fetch view context menu
       
   155  */
       
   156 void MpCollectionPopupHandler::openFetchViewContextMenu( int index, const QPointF &coords )
       
   157 {
       
   158     TX_ENTRY_ARGS( "index=" << index );
       
   159 
       
   160     HbAction *action;
       
   161     HbMenu *contextMenu = 0;
       
   162 
       
   163     switch ( mMpEngine->collectionData()->context() ) {
       
   164         case ECollectionContextAllSongs:
       
   165         case ECollectionContextArtistSongs:
       
   166         case ECollectionContextAlbumSongs:
       
   167         case ECollectionContextPlaylistSongs:
       
   168         case ECollectionContextGenreSongs:
       
   169             contextMenu = new HbMenu();
       
   170             action = contextMenu->addAction( hbTrId("txt_common_menu_play_music") );
       
   171             action->setEnabled( mMpEngine->verifyUsbBlocking() );
       
   172             break;
       
   173         default:
       
   174             break;
       
   175     }
       
   176 
       
   177     if ( contextMenu ) {
       
   178         if ( mView->isActivated() ) {
       
   179             mPermanentData->mContextMenuIndex = index;
       
   180             contextMenu->setPreferredPos( coords );
       
   181             contextMenu->setAttribute( Qt::WA_DeleteOnClose );
       
   182             setOutstandingPopup( contextMenu );
       
   183             contextMenu->open( this, SLOT( fetcherContextMenuOptionSelected( HbAction* ) ) );        
       
   184         }
       
   185         else {
       
   186             delete contextMenu;
       
   187             contextMenu = 0;
       
   188         }
   287         }
   189     }
   288     }
   190 
   289 
   191     TX_EXIT
   290     TX_EXIT
   192 }
   291 }
   225                      SLOT( handleAddSongsToPlayList( HbAction* ) ) );
   324                      SLOT( handleAddSongsToPlayList( HbAction* ) ) );
   226     TX_EXIT
   325     TX_EXIT
   227 }
   326 }
   228 
   327 
   229 /*!
   328 /*!
       
   329  Request to select songs to add to the playlist from TBone
       
   330  */
       
   331 void MpCollectionPopupHandler::openAddSongsToPlaylistFromTBone( )
       
   332 {
       
   333     TX_ENTRY
       
   334     MpCollectionTBoneListDataModel *model;
       
   335     model = new MpCollectionTBoneListDataModel( mMpEngine->collectionData() );
       
   336     //this item will be deleted when clearing permanent data.
       
   337     model->setParent(mPermanentData);
       
   338     model->refreshModel();
       
   339     getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), model,
       
   340                      SLOT( handleAddSongsToPlayList( HbAction* ) ) );
       
   341     TX_EXIT
       
   342 }
       
   343 
       
   344 /*!
   230  Request to select songs to be deleted
   345  Request to select songs to be deleted
   231  */
   346  */
   232 void MpCollectionPopupHandler::openDeleteSongs( QAbstractItemModel* model )
   347 void MpCollectionPopupHandler::openDeleteSongs( QAbstractItemModel* model )
   233 {
   348 {
   234     TX_ENTRY
   349     TX_ENTRY
   273 }
   388 }
   274 
   389 
   275 /*!
   390 /*!
   276  Request to reorder songs
   391  Request to reorder songs
   277  */
   392  */
   278 void MpCollectionPopupHandler::openArrangeSongs( MpMpxCollectionData* collectionData )
   393 void MpCollectionPopupHandler::openArrangeSongs( )
   279 {
   394 {
   280     TX_ENTRY
   395     TX_ENTRY
   281     launchArrangeSongsDialog( collectionData );
   396     launchArrangeSongsDialog();
   282     TX_EXIT
   397     TX_EXIT
   283 }
   398 }
   284 
   399 
   285 /*!
   400 /*!
   286  Closes any active popup
   401  Closes any active popup
   287  */
   402  */
   288 void MpCollectionPopupHandler::cancelOngoingPopup()
   403 void MpCollectionPopupHandler::cancelOngoingPopup( bool onlyContextMenu )
   289 {
   404 {
   290     TX_ENTRY    
   405     TX_ENTRY
   291     if ( mOutstandingPopup ) {
   406     if ( mOutstandingPopup ) {
   292          mOutstandingPopup->close();
   407         if ( onlyContextMenu ) {
   293          
   408             if ( mOutstandingPopup->objectName() == KContextMenu ) {
   294          //Delete/Clear permanent data until current popup gets deleted
   409                 mOutstandingPopup->close();
   295          mPermanentData->setParent( mOutstandingPopup );
   410                 mPermanentData->clear();
   296          //Generate new permanent data for future popups
   411             }
   297          mPermanentData = new MpPopupHandlerPermanentData( this );
   412         }
       
   413         else {
       
   414             mOutstandingPopup->close();
       
   415             //Delete/Clear permanent data until current popup gets deleted
       
   416             mPermanentData->setParent( mOutstandingPopup );
       
   417             //Generate new permanent data for future popups
       
   418             mPermanentData = new MpPopupHandlerPermanentData( this );
       
   419         }
   298     }
   420     }
   299     else {
   421     else {
   300         mPermanentData->clear();
   422         mPermanentData->clear();
   301     }
   423     }
   302 
   424     TX_EXIT
   303     TX_EXIT
       
   304 }
       
   305 
       
   306 /*!
       
   307  TODO: Workaround for HbListView multiple events: longPress and activated. Remove once HbListView get fixed (wk16)
       
   308  */
       
   309 bool MpCollectionPopupHandler::showingPopup()
       
   310 {
       
   311     return mOutstandingPopup;
       
   312 }
   425 }
   313 
   426 
   314 /*!
   427 /*!
   315  Slot to be called when an option has been selected from default context menu.
   428  Slot to be called when an option has been selected from default context menu.
   316  */
   429  */
   319     TX_ENTRY
   432     TX_ENTRY
   320     if ( selectedAction ) {
   433     if ( selectedAction ) {
   321         QString objectName = selectedAction->objectName();
   434         QString objectName = selectedAction->objectName();
   322         QList<int> selection;
   435         QList<int> selection;
   323         selection.append( mPermanentData->mContextMenuIndex );
   436         selection.append( mPermanentData->mContextMenuIndex );
   324         if ( objectName == "open" ) {
   437         if ( objectName == KOpen ) {
   325             mView->openItem( mPermanentData->mContextMenuIndex );
   438             mView->openItem( mPermanentData->mContextMenuIndex );
   326         }
   439         }
   327         if ( objectName == "add" ) {
   440         if ( objectName == KAdd ) {
   328             launchAddToPlaylistDialog( selection );
   441             launchAddToPlaylistDialog( selection );
   329         }
   442         }
   330         else if ( objectName == "delete" ) {
   443         else if ( objectName == KDelete ) {
   331             requestDelete( selection );
   444             requestDelete( selection );
   332         }
   445         }
   333         else if ( objectName == "rename playlist" ) {
   446         else if ( objectName == KRenamePlayList ) {
   334             QString currentName;
   447             QString currentName;
   335             currentName = mMpEngine->collectionData()->itemData( 
   448             currentName = mMpEngine->collectionData()->itemData( 
   336                     mPermanentData->mContextMenuIndex, MpMpxCollectionData::Title );
   449                     mPermanentData->mContextMenuIndex, MpMpxCollectionData::Title );
   337             openRenamePlaylistItemDialog( currentName );
   450             openRenamePlaylistItemDialog( currentName );
   338         }
   451         }
   363     clearOutstandingPopup( dialog );
   476     clearOutstandingPopup( dialog );
   364     bool operationCompleted( true );
   477     bool operationCompleted( true );
   365 
   478 
   366     if ( selectedAction ) {
   479     if ( selectedAction ) {
   367         QString objectName = selectedAction->objectName();
   480         QString objectName = selectedAction->objectName();
   368         if ( objectName == "new" ) {
   481         if ( objectName == KNew ) {
   369             QStringList playlists;
   482             QStringList playlists;
   370             mMpEngine->findPlaylists( playlists );
   483             mMpEngine->findPlaylists( playlists );
   371             queryNewPlaylistName( playlists, SLOT( handleAddToPlaylistGetTextFinished( HbAction* ) ) );
   484             queryNewPlaylistName( playlists, SLOT( handleAddToPlaylistGetTextFinished( HbAction* ) ) );
   372             operationCompleted = false;
   485             operationCompleted = false;
   373         }
   486         }
   393     clearOutstandingPopup( dialog );
   506     clearOutstandingPopup( dialog );
   394     bool operationCompleted( true );
   507     bool operationCompleted( true );
   395 
   508 
   396     if ( selectedAction ) {
   509     if ( selectedAction ) {
   397         QString objectName = selectedAction->objectName();
   510         QString objectName = selectedAction->objectName();
   398         if ( objectName == "ok" ) {
   511         if ( objectName == KOk ) {
   399             QString newPlaylistName = dialog->value().toString();
   512             QString newPlaylistName = dialog->value().toString();
   400             if ( newPlaylistName.length() ) {
   513             if ( newPlaylistName.length() ) {
   401                 //Create new playlist with given name
   514                 //Create new playlist with given name
   402                 mMpEngine->createPlaylist( newPlaylistName, mPermanentData->mSelectedItems );
   515                 mMpEngine->createPlaylist( newPlaylistName, mPermanentData->mSelectedItems );
   403             }
   516             }
   436     clearOutstandingPopup( dialog );
   549     clearOutstandingPopup( dialog );
   437     bool operationCompleted( true );
   550     bool operationCompleted( true );
   438 
   551 
   439     if ( selectedAction ) {
   552     if ( selectedAction ) {
   440         QString objectName = selectedAction->objectName();
   553         QString objectName = selectedAction->objectName();
   441         if ( objectName == "ok" ) {
   554         if ( objectName == KOk ) {
   442             QString newPlaylistName = dialog->value().toString();
   555             QString newPlaylistName = dialog->value().toString();
   443             if ( newPlaylistName.length() ) {
   556             if ( newPlaylistName.length() ) {
   444                 if ( newPlaylistName != mPermanentData->mOriginalName ) {
   557                 if ( newPlaylistName != mPermanentData->mOriginalName ) {
   445                     mMpEngine->renamePlaylist( newPlaylistName );
   558                     mMpEngine->renamePlaylist( newPlaylistName );
   446                 }
   559                 }
   470     clearOutstandingPopup( dialog );
   583     clearOutstandingPopup( dialog );
   471     bool operationCompleted( true );
   584     bool operationCompleted( true );
   472 
   585 
   473     if ( selectedAction ) {
   586     if ( selectedAction ) {
   474         QString objectName = selectedAction->objectName();
   587         QString objectName = selectedAction->objectName();
   475         if ( objectName == "ok" ) {
   588         if ( objectName == KOk ) {
   476             QString newPlaylistName = dialog->value().toString();
   589             QString newPlaylistName = dialog->value().toString();
   477             if ( newPlaylistName.length() ) {
   590             if ( newPlaylistName.length() ) {
   478                 if ( newPlaylistName != mPermanentData->mOriginalName ) {
   591                 if ( newPlaylistName != mPermanentData->mOriginalName ) {
   479                     mMpEngine->renamePlaylist( newPlaylistName, mPermanentData->mContextMenuIndex );
   592                     mMpEngine->renamePlaylist( newPlaylistName, mPermanentData->mContextMenuIndex );
   480                 }
   593                 }
   503     HbSelectionDialog *dialog = qobject_cast<HbSelectionDialog *>( sender() );
   616     HbSelectionDialog *dialog = qobject_cast<HbSelectionDialog *>( sender() );
   504     clearOutstandingPopup( dialog );
   617     clearOutstandingPopup( dialog );
   505 
   618 
   506     if ( selectedAction ) {
   619     if ( selectedAction ) {
   507         QString objectName = selectedAction->objectName();
   620         QString objectName = selectedAction->objectName();
   508         if ( objectName == "ok" ) {
   621         if ( objectName == KOk ) {
   509             QModelIndexList selectedModelIndexes;
   622             QModelIndexList selectedModelIndexes;
   510             selectedModelIndexes = dialog->selectedModelIndexes();
   623             selectedModelIndexes = dialog->selectedModelIndexes();
   511             if ( selectedModelIndexes.count() ) {
   624             if ( selectedModelIndexes.count() ) {
   512                 QList<int> selection;
   625                 QList<int> selection;
   513                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
   626                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
   514                     selection.append( selectedModelIndexes.at( i ).row() );
   627                     selection.append( selectedModelIndexes.at( i ).row() );
   515                 }
   628                 }
   516                 launchAddToPlaylistDialog( selection );
   629                 launchAddToPlaylistDialog( selection );
   517             }
   630             }
   518         }
   631         }
       
   632         else {
       
   633             mPermanentData->clear();
       
   634         }
   519     }
   635     }
   520 
   636 
   521     //Dialog is using CollectionView main model, avoid dialog destructor to alter it.
   637     //Dialog is using CollectionView main model, avoid dialog destructor to alter it.
   522     dialog->setModel( 0 );
   638     dialog->setModel( 0 );
   523 
   639 
   533     HbSelectionDialog *dialog = qobject_cast<HbSelectionDialog *>( sender() );
   649     HbSelectionDialog *dialog = qobject_cast<HbSelectionDialog *>( sender() );
   534     clearOutstandingPopup( dialog );
   650     clearOutstandingPopup( dialog );
   535 
   651 
   536     if ( selectedAction ) {
   652     if ( selectedAction ) {
   537         QString objectName = selectedAction->objectName();
   653         QString objectName = selectedAction->objectName();
   538         if ( objectName == "ok" ) {
   654         if ( objectName == KOk ) {
   539             QModelIndexList selectedModelIndexes;
   655             QModelIndexList selectedModelIndexes;
   540             selectedModelIndexes = dialog->selectedModelIndexes();
   656             selectedModelIndexes = dialog->selectedModelIndexes();
   541             if ( selectedModelIndexes.count() ) {
   657             if ( selectedModelIndexes.count() ) {
   542                 QList<int> selection;
   658                 QList<int> selection;
   543                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
   659                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
   563     HbSelectionDialog *dialog = qobject_cast<HbSelectionDialog *>( sender() );
   679     HbSelectionDialog *dialog = qobject_cast<HbSelectionDialog *>( sender() );
   564     clearOutstandingPopup( dialog );
   680     clearOutstandingPopup( dialog );
   565 
   681 
   566     if ( selectedAction ) {
   682     if ( selectedAction ) {
   567         QString objectName = selectedAction->objectName();
   683         QString objectName = selectedAction->objectName();
   568         if ( objectName == "ok" ) {
   684         if ( objectName == KOk ) {
   569             QModelIndexList selectedModelIndexes;
   685             QModelIndexList selectedModelIndexes;
   570             selectedModelIndexes = dialog->selectedModelIndexes();
   686             selectedModelIndexes = dialog->selectedModelIndexes();
   571             if ( selectedModelIndexes.count() ) {
   687             if ( selectedModelIndexes.count() ) {
   572                 QList<int> selection;
   688                 QList<int> selection;
   573                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
   689                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
   598     clearOutstandingPopup( dialog );
   714     clearOutstandingPopup( dialog );
   599     bool operationCompleted( true );
   715     bool operationCompleted( true );
   600 
   716 
   601     if ( selectedAction ) {
   717     if ( selectedAction ) {
   602         QString objectName = selectedAction->objectName();
   718         QString objectName = selectedAction->objectName();
   603         if ( objectName == "ok" ) {
   719         if ( objectName == KOk ) {
   604             QString newPlaylistName = dialog->value().toString();
   720             QString newPlaylistName = dialog->value().toString();
   605             if ( newPlaylistName.length() ) {
   721             if ( newPlaylistName.length() ) {
   606                 //Store the new playlist name and query for the items to be added
   722                 //Store the new playlist name and query for the items to be added
   607                 mPermanentData->mOriginalName = newPlaylistName;
   723                 mPermanentData->mOriginalName = newPlaylistName;
   608                 getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), 
   724                 getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), 
   633     HbSelectionDialog *dialog = qobject_cast<HbSelectionDialog *>( sender() );
   749     HbSelectionDialog *dialog = qobject_cast<HbSelectionDialog *>( sender() );
   634     clearOutstandingPopup( dialog );
   750     clearOutstandingPopup( dialog );
   635 
   751 
   636     if ( selectedAction ) {
   752     if ( selectedAction ) {
   637         QString objectName = selectedAction->objectName();
   753         QString objectName = selectedAction->objectName();
   638         if ( objectName == "ok" ) {
   754         if ( objectName == KOk ) {
   639             QList<int> selection;
   755             QList<int> selection;
   640             QModelIndexList selectedModelIndexes;
   756             QModelIndexList selectedModelIndexes;
   641             selectedModelIndexes = dialog->selectedModelIndexes();
   757             selectedModelIndexes = dialog->selectedModelIndexes();
   642             if ( selectedModelIndexes.count() ) {
   758             if ( selectedModelIndexes.count() ) {
   643                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
   759                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
   683     HbMessageBox *dialog = qobject_cast<HbMessageBox *>( sender() );
   799     HbMessageBox *dialog = qobject_cast<HbMessageBox *>( sender() );
   684     clearOutstandingPopup( dialog );
   800     clearOutstandingPopup( dialog );
   685     
   801     
   686     if ( selectedAction ) {
   802     if ( selectedAction ) {
   687         QString objectName = selectedAction->objectName();
   803         QString objectName = selectedAction->objectName();
   688         if ( objectName == "ok" ) {
   804         if ( objectName == KOk ) {
   689             mMpEngine->deleteSongs( mPermanentData->mSelectedItems );
   805             mMpEngine->deleteSongs( mPermanentData->mSelectedItems );
   690         }
   806         }
   691         selectedAction->setEnabled( false );
   807         selectedAction->setEnabled( false );
   692     }
   808     }
   693 
   809 
   694     mPermanentData->clear();
   810     mPermanentData->clear();
   695 
   811 
       
   812     TX_EXIT
       
   813 }
       
   814 
       
   815 /*!
       
   816  Slot called upon notification from MpEngine indicating start of
       
   817  deleting process.
       
   818  */
       
   819 void MpCollectionPopupHandler::handleDeleteStarted( TCollectionContext context, int count )
       
   820 {
       
   821     TX_ENTRY
       
   822     if ( context == ECollectionContextPlaylistSongs ) {
       
   823         if (count >= KSongsToDisplayProgressDlg) {  //show progress dialog if removing more than 100 songs
       
   824             launchProgressDialog( "txt_mus_info_removing_songs" );
       
   825         }
       
   826     }
       
   827     else if (context != ECollectionContextPlaylists ) {  //no progress dialog for delete playlist
       
   828         launchProgressDialog( "txt_mus_info_deleting" );
       
   829     }
       
   830     TX_EXIT
       
   831 }
       
   832 
       
   833 /*!
       
   834  Slot called upon notification from MpEngine indicating 'count' songs are going to be added.
       
   835  */
       
   836 void MpCollectionPopupHandler::handleAddingSongs( int count )
       
   837 {
       
   838     TX_ENTRY
       
   839     if ( count >= KSongsToDisplayProgressDlg )
       
   840     {
       
   841         HbProgressDialog *addSongsWaitNote = new HbProgressDialog( HbProgressDialog::WaitDialog );
       
   842         connect( addSongsWaitNote, SIGNAL( cancelled() ), mMpEngine, SLOT( cancelCollectionRequest() ) );
       
   843         addSongsWaitNote->setModal( true );
       
   844         addSongsWaitNote->setText( hbTrId( "txt_mus_info_adding_songs" ) );
       
   845         addSongsWaitNote->setObjectName( KProgressDialog );
       
   846         addSongsWaitNote->setAttribute( Qt::WA_DeleteOnClose );
       
   847         setOutstandingPopup( addSongsWaitNote );
       
   848         addSongsWaitNote->show();
       
   849     }
       
   850     TX_EXIT
       
   851 }
       
   852 
       
   853 /*!
       
   854  Slot called upon notification from MpEngine indicating end of
       
   855  deleting or adding process.
       
   856  */
       
   857 void MpCollectionPopupHandler::handleOperationEnded( bool success )
       
   858 {
       
   859     TX_ENTRY
       
   860     Q_UNUSED( success );
       
   861     if ( mOutstandingPopup && ( mOutstandingPopup->objectName() == KProgressDialog ) ) {
       
   862         HbProgressDialog *dialog = qobject_cast<HbProgressDialog *>( mOutstandingPopup );
       
   863         dialog->cancel();
       
   864     }
   696     TX_EXIT
   865     TX_EXIT
   697 }
   866 }
   698 
   867 
   699 /*!
   868 /*!
   700  Slot to be called when a popup is getting closed. Usefull when a dialog is closed before it finishes
   869  Slot to be called when a popup is getting closed. Usefull when a dialog is closed before it finishes
   745  Launches the 'Add to playlist' dialog.
   914  Launches the 'Add to playlist' dialog.
   746  */
   915  */
   747 void MpCollectionPopupHandler::launchAddToPlaylistDialog( QList<int> &selection )
   916 void MpCollectionPopupHandler::launchAddToPlaylistDialog( QList<int> &selection )
   748 {
   917 {
   749     TX_ENTRY
   918     TX_ENTRY
   750     if (!mView->isActivated()) {
   919 
   751         mPermanentData->clear();
       
   752         return;
       
   753     }
       
   754  
       
   755     QStringList playlists;
   920     QStringList playlists;
   756     mPermanentData->mSelectedItems = selection;
   921     mPermanentData->mSelectedItems = selection;
   757     mMpEngine->findPlaylists( playlists );
   922     mMpEngine->findPlaylists( playlists );
   758     if ( playlists.count() ) {
   923     if ( playlists.count() ) {
   759         //There are saved playlists, query for a saved playlist or new.
   924         //There are saved playlists, query for a saved playlist or new.
   762         dialog->setStringItems( playlists );
   927         dialog->setStringItems( playlists );
   763         dialog->setSelectionMode( HbAbstractItemView::SingleSelection );
   928         dialog->setSelectionMode( HbAbstractItemView::SingleSelection );
   764         dialog->setHeadingWidget(new HbLabel( hbTrId( "txt_mus_title_select_playlist" ) ) );
   929         dialog->setHeadingWidget(new HbLabel( hbTrId( "txt_mus_title_select_playlist" ) ) );
   765         dialog->clearActions();
   930         dialog->clearActions();
   766         action = new HbAction( hbTrId( "txt_mus_button_new" ) );
   931         action = new HbAction( hbTrId( "txt_mus_button_new" ) );
   767         action->setObjectName( "new" );
   932         action->setObjectName( KNew );
   768         dialog->addAction( action );
   933         dialog->addAction( action );
   769         action = new HbAction( hbTrId( "txt_common_button_cancel" ) );
   934         action = new HbAction( hbTrId( "txt_common_button_cancel" ) );
   770         action->setObjectName( "cancel" );
   935         action->setObjectName( KCancel );
   771         dialog->addAction( action );
   936         dialog->addAction( action );
       
   937         dialog->setObjectName( KAddToPlaylistSelectionDialog );
   772         dialog->setAttribute( Qt::WA_DeleteOnClose );
   938         dialog->setAttribute( Qt::WA_DeleteOnClose );
   773         setOutstandingPopup( dialog );
   939         setOutstandingPopup( dialog );
   774         dialog->open( this, SLOT( handleAddToPlaylistDialogFinished( HbAction* ) ) );
   940         dialog->open( this, SLOT( handleAddToPlaylistDialogFinished( HbAction* ) ) );
   775     }
   941     }
   776     else {
   942     else {
   808  */
   974  */
   809 void MpCollectionPopupHandler::getText( const QString &label, const QString &text,
   975 void MpCollectionPopupHandler::getText( const QString &label, const QString &text,
   810                                         const char *handler )
   976                                         const char *handler )
   811 {
   977 {
   812     TX_ENTRY
   978     TX_ENTRY
   813     if ( !mView->isActivated() ) {
       
   814         mPermanentData->clear();
       
   815         return;
       
   816     }
       
   817 
       
   818     HbAction *action;
   979     HbAction *action;
   819     HbInputDialog *dialog = new HbInputDialog();
   980     HbInputDialog *dialog = new HbInputDialog();
   820     dialog->setPromptText( label );
   981     dialog->setPromptText( label );
   821     dialog->setInputMode( HbInputDialog::TextInput );
   982     dialog->setInputMode( HbInputDialog::TextInput );
   822     dialog->setValue( text );
   983     dialog->setValue( text );
   823     dialog->clearActions();
   984     dialog->clearActions();
   824     action = new HbAction( hbTrId( "txt_common_button_ok" ) );
   985     action = new HbAction( hbTrId( "txt_common_button_ok" ) );
   825     action->setObjectName( "ok" );
   986     action->setObjectName( KOk );
   826     dialog->addAction( action );
   987     dialog->addAction( action );
   827     action = new HbAction( hbTrId( "txt_common_button_cancel" ) );
   988     action = new HbAction( hbTrId( "txt_common_button_cancel" ) );
   828     action->setObjectName( "cancel" );
   989     action->setObjectName( KCancel );
   829     dialog->addAction( action );
   990     dialog->addAction( action );
       
   991     dialog->setObjectName( KInputTextDialog );
   830     dialog->setAttribute( Qt::WA_DeleteOnClose );
   992     dialog->setAttribute( Qt::WA_DeleteOnClose );
   831     setOutstandingPopup( dialog );
   993     setOutstandingPopup( dialog );
   832     dialog->open( this, handler );
   994     dialog->open( this, handler );
   833     TX_EXIT
   995     TX_EXIT
   834 }
   996 }
   843 void MpCollectionPopupHandler::getModelIndexes( const QString &label, QAbstractItemModel* model,
  1005 void MpCollectionPopupHandler::getModelIndexes( const QString &label, QAbstractItemModel* model,
   844                                                 const char *handler)
  1006                                                 const char *handler)
   845 {   
  1007 {   
   846     TX_ENTRY
  1008     TX_ENTRY
   847 
  1009 
   848     if ( !mView->isActivated() ) {
  1010     connectExternalEvents();
   849         mPermanentData->clear();
       
   850         return;
       
   851     }
       
   852 
  1011 
   853     HbAction *action;
  1012     HbAction *action;
   854     HbSelectionDialog *dialog = new HbSelectionDialog();
  1013     HbSelectionDialog *dialog = new HbSelectionDialog();
   855     dialog->setHeadingWidget( new HbLabel( label ) );
  1014     dialog->setHeadingWidget( new HbLabel( label ) );
   856     dialog->setSelectionMode( HbAbstractItemView::MultiSelection );
  1015     dialog->setSelectionMode( HbAbstractItemView::MultiSelection );
   857     dialog->setModel( model );
  1016     dialog->setModel( model );
   858     dialog->clearActions();
  1017     dialog->clearActions();
   859     action = new HbAction( hbTrId( "txt_common_button_ok" ) );
  1018     action = new HbAction( hbTrId( "txt_common_button_ok" ) );
   860     action->setObjectName( "ok" );
  1019     action->setObjectName( KOk );
   861     dialog->addAction( action );
  1020     dialog->addAction( action );
   862     action = new HbAction( hbTrId( "txt_common_button_cancel" ) );
  1021     action = new HbAction( hbTrId( "txt_common_button_cancel" ) );
   863     action->setObjectName( "cancel" );
  1022     action->setObjectName( KCancel );
   864     dialog->addAction( action );
  1023     dialog->addAction( action );
       
  1024     dialog->setObjectName( KGetModelIndexesListDialog );
   865     dialog->setAttribute( Qt::WA_DeleteOnClose );
  1025     dialog->setAttribute( Qt::WA_DeleteOnClose );
   866     setOutstandingPopup( dialog );
  1026     setOutstandingPopup( dialog );
   867     dialog->open( this, handler );
  1027     dialog->open( this, handler );
   868 
  1028 
   869     TX_EXIT
  1029     TX_EXIT
   870 }
  1030 }
   871 
  1031 
   872 /*!
  1032 /*!
   873  \internal
  1033  \internal
   874  Launches a list dialog to reorder them.
  1034  Launches a list dialog to reorder them.
   875  \a collectionData Base to generate dialog's model.
  1035  */
   876  */
  1036 void MpCollectionPopupHandler::launchArrangeSongsDialog()
   877 void MpCollectionPopupHandler::launchArrangeSongsDialog( MpMpxCollectionData* collectionData )
       
   878 {   
  1037 {   
   879     TX_ENTRY
  1038     TX_ENTRY
   880 
       
   881     if ( !mView->isActivated() ) {
       
   882         return;
       
   883     }
       
   884 
  1039 
   885     HbListView *listView = new HbListView();
  1040     HbListView *listView = new HbListView();
   886     listView->setItemRecycling( true );
  1041     listView->setItemRecycling( true );
   887     listView->setScrollingStyle( HbListView::PanOrFlick );
  1042     listView->setScrollingStyle( HbListView::PanOrFlick );
   888     listView->setClampingStyle( HbListView::BounceBackClamping );
  1043     listView->setClampingStyle( HbListView::BounceBackClamping );
   890     scrollbar->show();
  1045     scrollbar->show();
   891     scrollbar->setInteractive( true);
  1046     scrollbar->setInteractive( true);
   892     listView->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded);
  1047     listView->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded);
   893     MpCollectionDataModel *model;
  1048     MpCollectionDataModel *model;
   894     //Ownership of the model is passed to the listView as a child object.
  1049     //Ownership of the model is passed to the listView as a child object.
   895     model = new MpCollectionDataModel( collectionData, listView );
  1050     model = new MpCollectionDataModel( mMpEngine->collectionData() , listView );
   896     model->refreshModel();
  1051     model->refreshModel();
   897     connect( model,
  1052     connect( model,
   898              SIGNAL( orderChanged( int, int, int, int ) ),
  1053              SIGNAL( orderChanged( int, int, int, int ) ),
   899              mMpEngine,
  1054              mMpEngine,
   900              SLOT( reorderPlaylist( int, int, int, int ) ) );
  1055              SLOT( reorderPlaylist( int, int, int, int ) ) );
   909     dialog->setContentWidget( listView );
  1064     dialog->setContentWidget( listView );
   910     dialog->clearActions();
  1065     dialog->clearActions();
   911     HbAction *action;
  1066     HbAction *action;
   912     action = new HbAction( hbTrId( "txt_common_button_ok" ) );
  1067     action = new HbAction( hbTrId( "txt_common_button_ok" ) );
   913     dialog->addAction( action );
  1068     dialog->addAction( action );
       
  1069     dialog->setObjectName( KArrangeSongsDialog );
   914     dialog->setAttribute( Qt::WA_DeleteOnClose );
  1070     dialog->setAttribute( Qt::WA_DeleteOnClose );
   915     setOutstandingPopup(dialog);
  1071     setOutstandingPopup(dialog);
   916     dialog->open( this, SLOT( handleArrangeSongs( HbAction* ) ) );
  1072     dialog->open( this, SLOT( handleArrangeSongs( HbAction* ) ) );
   917 
  1073 
   918     TX_EXIT
  1074     TX_EXIT
   927 {
  1083 {
   928     TX_ENTRY
  1084     TX_ENTRY
   929     QString message;
  1085     QString message;
   930     mPermanentData->mSelectedItems = selection;
  1086     mPermanentData->mSelectedItems = selection;
   931     bool needsConfirmation = true;
  1087     bool needsConfirmation = true;
       
  1088     connectExternalEvents();
   932 
  1089 
   933     switch ( mMpEngine->collectionData()->context() ) {
  1090     switch ( mMpEngine->collectionData()->context() ) {
   934         case ECollectionContextAllSongs:
  1091         case ECollectionContextAllSongs:
   935         case ECollectionContextArtistSongs:
  1092         case ECollectionContextArtistAlbumsTBone:
   936         case ECollectionContextAlbumSongs:
  1093         case ECollectionContextArtistAllSongs:
       
  1094         case ECollectionContextAlbumsTBone:
   937             message = hbTrId( "txt_mus_delete_song" );
  1095             message = hbTrId( "txt_mus_delete_song" );
   938             break;
  1096             break;
   939         case ECollectionContextArtists:
  1097         case ECollectionContextArtists:
   940             message = hbTrId( "txt_mus_delete_artist" );
  1098             message = hbTrId( "txt_mus_delete_artist" );
   941             break;
  1099             break;
   945             break;
  1103             break;
   946         case ECollectionContextPlaylists:
  1104         case ECollectionContextPlaylists:
   947             message = hbTrId( "txt_mus_delete_playlist" );
  1105             message = hbTrId( "txt_mus_delete_playlist" );
   948             break;
  1106             break;
   949         case ECollectionContextPlaylistSongs:
  1107         case ECollectionContextPlaylistSongs:
   950         case ECollectionContextGenres:
       
   951         case ECollectionContextGenreSongs:
       
   952             needsConfirmation = false;
  1108             needsConfirmation = false;
   953             mMpEngine->deleteSongs( mPermanentData->mSelectedItems );
  1109             mMpEngine->deleteSongs( mPermanentData->mSelectedItems );
   954             mPermanentData->clear();
  1110             mPermanentData->clear();
   955             break;
  1111             break;
   956         case ECollectionContextUnknown:
  1112         case ECollectionContextUnknown:
   961             TX_LOG_ARGS( "Invalid Collection Context" );
  1117             TX_LOG_ARGS( "Invalid Collection Context" );
   962             break;
  1118             break;
   963     }
  1119     }
   964 
  1120 
   965     if ( needsConfirmation ) {
  1121     if ( needsConfirmation ) {
   966         if ( !mView->isActivated() ) {
       
   967             mPermanentData->clear();
       
   968             return;
       
   969         }
       
   970 
       
   971         HbAction *action;
  1122         HbAction *action;
   972         HbMessageBox *dialog = new HbMessageBox( HbMessageBox::MessageTypeQuestion );
  1123         HbMessageBox *dialog = new HbMessageBox( HbMessageBox::MessageTypeQuestion );
   973 
  1124 
   974         dialog->setText( message );
  1125         dialog->setText( message );
   975         dialog->setTimeout( HbPopup::NoTimeout );
  1126         dialog->setTimeout( HbPopup::NoTimeout );
   976         dialog->clearActions();
  1127         dialog->clearActions();
   977         action = new HbAction( hbTrId( "txt_common_button_yes" ) );
  1128         action = new HbAction( hbTrId( "txt_common_button_yes" ) );
   978         action->setObjectName( "ok" );
  1129         action->setObjectName( KOk );
   979         dialog->addAction( action );
  1130         dialog->addAction( action );
   980         action = new HbAction( hbTrId( "txt_common_button_no" ) );
  1131         action = new HbAction( hbTrId( "txt_common_button_no" ) );
   981         action->setObjectName( "cancel" );
  1132         action->setObjectName( KCancel );
   982         dialog->addAction( action );
  1133         dialog->addAction( action );
       
  1134         dialog->setObjectName( KRequestDeleteMessageBox );
   983         dialog->setAttribute( Qt::WA_DeleteOnClose );
  1135         dialog->setAttribute( Qt::WA_DeleteOnClose );
   984         setOutstandingPopup( dialog );
  1136         setOutstandingPopup( dialog );
   985         dialog->open( this, SLOT( handleRequestDelete( HbAction* ) ) );
  1137         dialog->open( this, SLOT( handleRequestDelete( HbAction* ) ) );
   986     }
  1138     }
   987 
  1139 
   988     TX_EXIT
  1140     TX_EXIT
   989 }
  1141 }
   990 
  1142 
   991 
       
   992 //------------------------------------------------------------------
       
   993 //    MpPopupHandlerPermanentData
       
   994 //------------------------------------------------------------------
       
   995 /*!
       
   996  Constructs the popup handler permanent data.
       
   997  */
       
   998 MpCollectionPopupHandler::MpPopupHandlerPermanentData::MpPopupHandlerPermanentData( QObject *parent )
       
   999     : QObject( parent ),
       
  1000       mIsolatedCollectionData( 0 ),
       
  1001       mAbstractItemModel( 0 ),
       
  1002       mContextMenuIndex( KNullIndex )
       
  1003 {
       
  1004       TX_ENTRY
       
  1005       mSelectedItems.clear();
       
  1006       mOriginalName.clear();
       
  1007       TX_EXIT
       
  1008 }
       
  1009 
       
  1010 /*!
       
  1011  Destructs the popup handler permanent data.
       
  1012  */
       
  1013 MpCollectionPopupHandler::MpPopupHandlerPermanentData::~MpPopupHandlerPermanentData()
       
  1014 {
       
  1015     TX_ENTRY
       
  1016     clear();
       
  1017     TX_EXIT
       
  1018 }
       
  1019 
       
  1020 /*!
  1143 /*!
  1021  \internal
  1144  \internal
  1022   Clears all permanent data. 
  1145  Launches a waiting progress note.
  1023  */
  1146  \a content String id to display in the dialog.
  1024 void MpCollectionPopupHandler::MpPopupHandlerPermanentData::clear()
  1147  */
  1025 {
  1148 void MpCollectionPopupHandler::launchProgressDialog( const char *id )
  1026     TX_ENTRY
  1149 {
  1027     mSelectedItems.clear();
  1150     HbProgressDialog *deleteProgressNote = new HbProgressDialog( HbProgressDialog::WaitDialog );
  1028     mOriginalName.clear();
  1151     connect( deleteProgressNote, SIGNAL( cancelled() ), mMpEngine, SLOT( cancelCollectionRequest() ) );
  1029     mContextMenuIndex = KNullIndex;
  1152     deleteProgressNote->setModal( true );
  1030     if ( mIsolatedCollectionData ) {
  1153     deleteProgressNote->setDismissPolicy( HbPopup::NoDismiss );
  1031         MpEngine::instance()->releaseIsolatedCollection();
  1154     deleteProgressNote->setText( hbTrId( id ) );
  1032         mIsolatedCollectionData = 0;
  1155     deleteProgressNote->setObjectName( KProgressDialog );
  1033     }
  1156     deleteProgressNote->setAttribute( Qt::WA_DeleteOnClose );
  1034     if ( mAbstractItemModel ) {
  1157     setOutstandingPopup( deleteProgressNote );
  1035         delete mAbstractItemModel;
  1158     deleteProgressNote->show();
  1036         mAbstractItemModel = 0;
  1159 }
  1037     }
  1160 
  1038     TX_EXIT
  1161 /*!
  1039 }
  1162  \internal
       
  1163  Connects MpEngine signals on demand in order to save time at start up.
       
  1164   */
       
  1165 void MpCollectionPopupHandler::connectExternalEvents()
       
  1166 {
       
  1167     if ( !mExternalEventsConnected ) {
       
  1168         connect( mMpEngine, SIGNAL( deleteStarted( TCollectionContext, int ) ),
       
  1169                 this, SLOT( handleDeleteStarted( TCollectionContext, int ) ) );
       
  1170         connect( mMpEngine, SIGNAL( songsDeleted( bool ) ), this, SLOT( handleOperationEnded( bool ) ) );
       
  1171         connect( mMpEngine, SIGNAL( aboutToAddSongs( int ) ), this, SLOT( handleAddingSongs( int ) ) );
       
  1172         connect( mMpEngine, SIGNAL( playlistSaved( bool ) ), this, SLOT( handleOperationEnded( bool ) ) );
       
  1173         mExternalEventsConnected = true;
       
  1174     }
       
  1175 }
       
  1176