mpviewplugins/mpcollectionviewplugin/src/mpcollectionpopuphandler.cpp
changeset 29 8192e5b5c935
parent 25 3ec52facab4d
child 37 eb79a7c355bf
equal deleted inserted replaced
25:3ec52facab4d 29:8192e5b5c935
    23 #include <hbinputdialog.h>
    23 #include <hbinputdialog.h>
    24 #include <hblabel.h>
    24 #include <hblabel.h>
    25 #include <hblistview.h>
    25 #include <hblistview.h>
    26 #include <hbscrollbar.h>
    26 #include <hbscrollbar.h>
    27 
    27 
    28 #include "mpengine.h"
    28 #include "mpenginefactory.h"
    29 #include "mpcollectionview.h"
    29 #include "mpcollectionview.h"
    30 #include "mpmpxcollectiondata.h"
    30 #include "mpmpxcollectiondata.h"
    31 #include "mpcollectiondatamodel.h"
    31 #include "mpcollectiondatamodel.h"
       
    32 #include "mpcollectiontbonelistdatamodel.h"
    32 #include "mpmpxcollectionviewdefs.h"
    33 #include "mpmpxcollectionviewdefs.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;
    52       mOutstandingPopup( 0 ),
    53       mOutstandingPopup( 0 ),
    53       mMpEngine( 0 ),
    54       mMpEngine( 0 ),
    54       mPermanentData( 0 )
    55       mPermanentData( 0 )
    55 {
    56 {
    56     TX_ENTRY
    57     TX_ENTRY
    57     mMpEngine = MpEngine::instance();
    58     mMpEngine = MpEngineFactory::sharedEngine();
    58     mPermanentData = new MpPopupHandlerPermanentData( this );
    59     mPermanentData = new MpPopupHandlerPermanentData( this );
    59     TX_EXIT
    60     TX_EXIT
    60 }
    61 }
    61 
    62 
    62 /*!
    63 /*!
    79     HbAction *action;
    80     HbAction *action;
    80     bool usbBlocked = mMpEngine->verifyUsbBlocking();
    81     bool usbBlocked = mMpEngine->verifyUsbBlocking();
    81 
    82 
    82     switch ( mMpEngine->collectionData()->context() ) {
    83     switch ( mMpEngine->collectionData()->context() ) {
    83         case ECollectionContextAllSongs:
    84         case ECollectionContextAllSongs:
    84         case ECollectionContextArtistSongs:
    85         case ECollectionContextArtistAllSongs:
    85         case ECollectionContextAlbumSongs:
    86         case ECollectionContextArtistAlbumsTBone:
       
    87         case ECollectionContextAlbumsTBone:
    86             contextMenu = new HbMenu();
    88             contextMenu = new HbMenu();
    87             action = contextMenu->addAction( hbTrId( "txt_common_menu_play_music" ) );
    89             action = contextMenu->addAction( hbTrId( "txt_common_menu_play_music" ) );
    88             action->setObjectName( "open" );
    90             action->setObjectName( "open" );
    89             action = contextMenu->addAction( hbTrId( "txt_mus_menu_add_to_playlist" ) );
    91             action = contextMenu->addAction( hbTrId( "txt_mus_menu_add_to_playlist" ) );
    90             action->setObjectName( "add" );
    92             action->setObjectName( "add" );
   160     HbAction *action;
   162     HbAction *action;
   161     HbMenu *contextMenu = 0;
   163     HbMenu *contextMenu = 0;
   162 
   164 
   163     switch ( mMpEngine->collectionData()->context() ) {
   165     switch ( mMpEngine->collectionData()->context() ) {
   164         case ECollectionContextAllSongs:
   166         case ECollectionContextAllSongs:
   165         case ECollectionContextArtistSongs:
   167         case ECollectionContextArtistAlbumsTBone:
   166         case ECollectionContextAlbumSongs:
   168         case ECollectionContextArtistAllSongs:
       
   169         case ECollectionContextAlbumsTBone:
   167         case ECollectionContextPlaylistSongs:
   170         case ECollectionContextPlaylistSongs:
   168         case ECollectionContextGenreSongs:
       
   169             contextMenu = new HbMenu();
   171             contextMenu = new HbMenu();
   170             action = contextMenu->addAction( hbTrId("txt_common_menu_play_music") );
   172             action = contextMenu->addAction( hbTrId("txt_common_menu_play_music") );
   171             action->setEnabled( mMpEngine->verifyUsbBlocking() );
   173             action->setEnabled( !mMpEngine->verifyUsbBlocking() );
   172             break;
   174             break;
   173         default:
   175         default:
   174             break;
   176             break;
   175     }
   177     }
   176 
   178 
   225                      SLOT( handleAddSongsToPlayList( HbAction* ) ) );
   227                      SLOT( handleAddSongsToPlayList( HbAction* ) ) );
   226     TX_EXIT
   228     TX_EXIT
   227 }
   229 }
   228 
   230 
   229 /*!
   231 /*!
       
   232  Request to select songs to add to the playlist from TBone
       
   233  */
       
   234 void MpCollectionPopupHandler::openAddSongsToPlaylistFromTBone( )
       
   235 {
       
   236     TX_ENTRY
       
   237     MpCollectionTBoneListDataModel *model;
       
   238     model = new MpCollectionTBoneListDataModel( mMpEngine->collectionData() );
       
   239 	//this item will be deleted when clearing permanent data.
       
   240     model->setParent(mPermanentData);
       
   241     model->refreshModel();
       
   242     getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), model,
       
   243                      SLOT( handleAddSongsToPlayList( HbAction* ) ) );
       
   244     TX_EXIT
       
   245 }
       
   246 
       
   247 /*!
   230  Request to select songs to be deleted
   248  Request to select songs to be deleted
   231  */
   249  */
   232 void MpCollectionPopupHandler::openDeleteSongs( QAbstractItemModel* model )
   250 void MpCollectionPopupHandler::openDeleteSongs( QAbstractItemModel* model )
   233 {
   251 {
   234     TX_ENTRY
   252     TX_ENTRY
   273 }
   291 }
   274 
   292 
   275 /*!
   293 /*!
   276  Request to reorder songs
   294  Request to reorder songs
   277  */
   295  */
   278 void MpCollectionPopupHandler::openArrangeSongs( MpMpxCollectionData* collectionData )
   296 void MpCollectionPopupHandler::openArrangeSongs( )
   279 {
   297 {
   280     TX_ENTRY
   298     TX_ENTRY
   281     launchArrangeSongsDialog( collectionData );
   299     launchArrangeSongsDialog();
   282     TX_EXIT
   300     TX_EXIT
   283 }
   301 }
   284 
   302 
   285 /*!
   303 /*!
   286  Closes any active popup
   304  Closes any active popup
   513                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
   531                 for ( int i = 0; i < selectedModelIndexes.size(); ++i ) {
   514                     selection.append( selectedModelIndexes.at( i ).row() );
   532                     selection.append( selectedModelIndexes.at( i ).row() );
   515                 }
   533                 }
   516                 launchAddToPlaylistDialog( selection );
   534                 launchAddToPlaylistDialog( selection );
   517             }
   535             }
       
   536         }
       
   537         else {
       
   538             mPermanentData->clear();
   518         }
   539         }
   519     }
   540     }
   520 
   541 
   521     //Dialog is using CollectionView main model, avoid dialog destructor to alter it.
   542     //Dialog is using CollectionView main model, avoid dialog destructor to alter it.
   522     dialog->setModel( 0 );
   543     dialog->setModel( 0 );
   870 }
   891 }
   871 
   892 
   872 /*!
   893 /*!
   873  \internal
   894  \internal
   874  Launches a list dialog to reorder them.
   895  Launches a list dialog to reorder them.
   875  \a collectionData Base to generate dialog's model.
   896  */
   876  */
   897 void MpCollectionPopupHandler::launchArrangeSongsDialog()
   877 void MpCollectionPopupHandler::launchArrangeSongsDialog( MpMpxCollectionData* collectionData )
       
   878 {   
   898 {   
   879     TX_ENTRY
   899     TX_ENTRY
   880 
   900 
   881     if ( !mView->isActivated() ) {
   901     if ( !mView->isActivated() ) {
   882         return;
   902         return;
   890     scrollbar->show();
   910     scrollbar->show();
   891     scrollbar->setInteractive( true);
   911     scrollbar->setInteractive( true);
   892     listView->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded);
   912     listView->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded);
   893     MpCollectionDataModel *model;
   913     MpCollectionDataModel *model;
   894     //Ownership of the model is passed to the listView as a child object.
   914     //Ownership of the model is passed to the listView as a child object.
   895     model = new MpCollectionDataModel( collectionData, listView );
   915     model = new MpCollectionDataModel( mMpEngine->collectionData() , listView );
   896     model->refreshModel();
   916     model->refreshModel();
   897     connect( model,
   917     connect( model,
   898              SIGNAL( orderChanged( int, int, int, int ) ),
   918              SIGNAL( orderChanged( int, int, int, int ) ),
   899              mMpEngine,
   919              mMpEngine,
   900              SLOT( reorderPlaylist( int, int, int, int ) ) );
   920              SLOT( reorderPlaylist( int, int, int, int ) ) );
   930     mPermanentData->mSelectedItems = selection;
   950     mPermanentData->mSelectedItems = selection;
   931     bool needsConfirmation = true;
   951     bool needsConfirmation = true;
   932 
   952 
   933     switch ( mMpEngine->collectionData()->context() ) {
   953     switch ( mMpEngine->collectionData()->context() ) {
   934         case ECollectionContextAllSongs:
   954         case ECollectionContextAllSongs:
   935         case ECollectionContextArtistSongs:
   955         case ECollectionContextArtistAlbumsTBone:
   936         case ECollectionContextAlbumSongs:
   956         case ECollectionContextArtistAllSongs:
       
   957         case ECollectionContextAlbumsTBone:
   937             message = hbTrId( "txt_mus_delete_song" );
   958             message = hbTrId( "txt_mus_delete_song" );
   938             break;
   959             break;
   939         case ECollectionContextArtists:
   960         case ECollectionContextArtists:
   940             message = hbTrId( "txt_mus_delete_artist" );
   961             message = hbTrId( "txt_mus_delete_artist" );
   941             break;
   962             break;
   945             break;
   966             break;
   946         case ECollectionContextPlaylists:
   967         case ECollectionContextPlaylists:
   947             message = hbTrId( "txt_mus_delete_playlist" );
   968             message = hbTrId( "txt_mus_delete_playlist" );
   948             break;
   969             break;
   949         case ECollectionContextPlaylistSongs:
   970         case ECollectionContextPlaylistSongs:
   950         case ECollectionContextGenres:
       
   951         case ECollectionContextGenreSongs:
       
   952             needsConfirmation = false;
   971             needsConfirmation = false;
   953             mMpEngine->deleteSongs( mPermanentData->mSelectedItems );
   972             mMpEngine->deleteSongs( mPermanentData->mSelectedItems );
   954             mPermanentData->clear();
   973             mPermanentData->clear();
   955             break;
   974             break;
   956         case ECollectionContextUnknown:
   975         case ECollectionContextUnknown:
  1026     TX_ENTRY
  1045     TX_ENTRY
  1027     mSelectedItems.clear();
  1046     mSelectedItems.clear();
  1028     mOriginalName.clear();
  1047     mOriginalName.clear();
  1029     mContextMenuIndex = KNullIndex;
  1048     mContextMenuIndex = KNullIndex;
  1030     if ( mIsolatedCollectionData ) {
  1049     if ( mIsolatedCollectionData ) {
  1031         MpEngine::instance()->releaseIsolatedCollection();
  1050         MpEngineFactory::sharedEngine()->releaseIsolatedCollection();
  1032         mIsolatedCollectionData = 0;
  1051         mIsolatedCollectionData = 0;
  1033     }
  1052     }
  1034     if ( mAbstractItemModel ) {
  1053     if ( mAbstractItemModel ) {
  1035         delete mAbstractItemModel;
  1054         delete mAbstractItemModel;
  1036         mAbstractItemModel = 0;
  1055         mAbstractItemModel = 0;
  1037     }
  1056     }
  1038     TX_EXIT
  1057     //clearing any child Objects.
  1039 }
  1058     foreach (QObject* child, children()) {
       
  1059         child->deleteLater();
       
  1060     }
       
  1061     TX_EXIT
       
  1062 }