45 #include "mpcommondefs.h" |
43 #include "mpcommondefs.h" |
46 #include "mptrace.h" |
44 #include "mptrace.h" |
47 #include "mpsnapshotwidget.h" |
45 #include "mpsnapshotwidget.h" |
48 #include "mpsettingsmanager.h" |
46 #include "mpsettingsmanager.h" |
49 #include "mpcollectionlistcontainer.h" |
47 #include "mpcollectionlistcontainer.h" |
|
48 #include "mpcollectionpopuphandler.h" |
50 |
49 |
51 |
50 |
52 const char*MUSIC_COLLECTION_DOCML = ":/docml/musiccollection.docml"; |
51 const char*MUSIC_COLLECTION_DOCML = ":/docml/musiccollection.docml"; |
53 const char*EFFECT_SELECT = ":/effects/select.fxml"; |
52 const char*EFFECT_SELECT = ":/effects/select.fxml"; |
54 const char*EFFECT_SELECT_END = ":/effects/select_end.fxml"; |
53 const char*EFFECT_SELECT_END = ":/effects/select_end.fxml"; |
55 |
54 |
56 const int KMainToolBarAll = 0; |
55 const int KMainToolBarAll = 0; |
57 const int KMainToolBarArtists = 1; |
56 const int KMainToolBarArtists = 1; |
58 |
57 const int KMainToolBarAlbums = 2; |
59 const int KMainToolBarPlaylists = 3; |
58 const int KMainToolBarPlaylists = 3; |
60 |
59 |
61 const int KPlaylistToolBarAdd = 0; |
60 const int KPlaylistToolBarAdd = 0; |
62 const int KPlaylistToolBarRemove = 1; |
61 const int KPlaylistToolBarRemove = 1; |
63 const int KplaylistToolBarReorder = 2; |
62 const int KplaylistToolBarReorder = 2; |
253 TX_LOG_ARGS( "Error: invalid xml file." ); |
252 TX_LOG_ARGS( "Error: invalid xml file." ); |
254 Q_ASSERT_X( ok, "MpCollectionView::initializeView", "invalid xml file" ); |
253 Q_ASSERT_X( ok, "MpCollectionView::initializeView", "invalid xml file" ); |
255 } |
254 } |
256 |
255 |
257 mContainerFactory = new MpCollectionContainerFactory( this, mDocumentLoader ); |
256 mContainerFactory = new MpCollectionContainerFactory( this, mDocumentLoader ); |
|
257 |
|
258 mMpPopupHandler = new MpCollectionPopupHandler( this ); |
258 |
259 |
259 connect( mMpEngine, SIGNAL( usbBlocked(bool) ), |
260 connect( mMpEngine, SIGNAL( usbBlocked(bool) ), |
260 this, SLOT( handleUsbBlocked(bool) ) ); |
261 this, SLOT( handleUsbBlocked(bool) ) ); |
261 connect( mMpEngine, SIGNAL( libraryAboutToRefresh() ), |
262 connect( mMpEngine, SIGNAL( libraryAboutToUpdate() ), |
262 this, SLOT( handleLibraryAboutToUpdate() ) ); |
263 this, SLOT( handleLibraryAboutToUpdate() ) ); |
263 connect( mMpEngine, SIGNAL( libraryRefreshed() ), |
264 connect( mMpEngine, SIGNAL( libraryUpdated() ), |
264 this, SLOT( handleLibraryUpdated() ) ); |
265 this, SLOT( handleLibraryUpdated() ) ); |
265 mUsbBlocked = mMpEngine->verifyUsbBlocking(); |
266 mUsbBlocked = mMpEngine->verifyUsbBlocking(); |
266 |
267 |
267 if ( MpSettingsManager::firstStartup() ) { |
268 if ( MpSettingsManager::firstStartup() ) { |
268 mActivationWaiting = true; |
269 mActivationWaiting = true; |
557 /*! |
598 /*! |
558 Slot to be called when 'Add to playlist' is clicked by the user from the menu. |
599 Slot to be called when 'Add to playlist' is clicked by the user from the menu. |
559 */ |
600 */ |
560 void MpCollectionView::addToPlaylist() |
601 void MpCollectionView::addToPlaylist() |
561 { |
602 { |
562 if ( !mMpEngine->verifyUsbBlocking( true ) ) { |
603 mMpPopupHandler->openAddSongsToPlaylist( mCollectionDataModel ); |
563 QModelIndexList SelectedModelIndexes; |
|
564 bool ok; |
|
565 SelectedModelIndexes = getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), |
|
566 mCollectionDataModel, |
|
567 ok); |
|
568 |
|
569 if ( ok && SelectedModelIndexes.count() ) { |
|
570 QList<int> selection; |
|
571 for ( int i = 0; i < SelectedModelIndexes.size(); ++i ) { |
|
572 selection.append( SelectedModelIndexes.at( i ).row() ); |
|
573 } |
|
574 launchAddToPlaylistDialog( selection ); |
|
575 } |
|
576 } |
|
577 } |
604 } |
578 |
605 |
579 /*! |
606 /*! |
580 Slot to be called when 'Delete' is clicked by the user from the menu. |
607 Slot to be called when 'Delete' is clicked by the user from the menu. |
581 */ |
608 */ |
582 void MpCollectionView::deleteSongs() |
609 void MpCollectionView::deleteSongs() |
583 { |
610 { |
584 QModelIndexList SelectedModelIndexes; |
611 mMpPopupHandler->openDeleteSongs( mCollectionDataModel ); |
585 bool ok; |
|
586 SelectedModelIndexes = getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), |
|
587 mCollectionDataModel, |
|
588 ok); |
|
589 |
|
590 if ( ok && SelectedModelIndexes.count() ) { |
|
591 QList<int> selection; |
|
592 for ( int i = 0; i < SelectedModelIndexes.size(); ++i ) { |
|
593 selection.append( SelectedModelIndexes.at( i ).row() ); |
|
594 } |
|
595 requestDelete( selection ); |
|
596 updateMenu(); |
|
597 } |
|
598 } |
612 } |
599 |
613 |
600 /*! |
614 /*! |
601 Slot to be called when 'Rename Playlist' is clicked by the user from the menu. |
615 Slot to be called when 'Rename Playlist' is clicked by the user from the menu. |
602 */ |
616 */ |
603 void MpCollectionView::renameCurrentPlaylistContainer() |
617 void MpCollectionView::renameCurrentPlaylistContainer() |
604 { |
618 { |
605 if ( !mMpEngine->verifyUsbBlocking( true ) ) { |
619 QString currentName; |
606 QString currentName; |
620 currentName = mCollectionData->collectionTitle(); |
607 currentName = mCollectionData->collectionTitle(); |
621 mMpPopupHandler->openRenamePlaylistContainerDialog( currentName ); |
608 bool ok = false; |
|
609 QString newName; |
|
610 newName = getText( hbTrId( "txt_mus_dialog_enter_name" ), currentName, ok ); |
|
611 if ( ok && ( currentName != newName ) ) { |
|
612 mMpEngine->renamePlaylist( newName ); |
|
613 } |
|
614 } |
|
615 } |
622 } |
616 |
623 |
617 |
624 |
618 /*! |
625 /*! |
619 Slot to be called when 'Add to playlist' operation has completed. |
626 Slot to be called when 'Add to playlist' operation has completed. |
650 /*! |
657 /*! |
651 Slot to be called to get ready for add to playlist using an isolated collection. |
658 Slot to be called to get ready for add to playlist using an isolated collection. |
652 */ |
659 */ |
653 void MpCollectionView::prepareToAddToPlaylist() |
660 void MpCollectionView::prepareToAddToPlaylist() |
654 { |
661 { |
655 TX_ENTRY |
662 TX_ENTRY |
656 //We dismiss dialogs here since after open is complete we are triggering a dialog. |
|
657 setOutstandingPopup( 0 ); |
|
658 mMpEngine->openIsolatedCollection( ECollectionContextAllSongs ); |
663 mMpEngine->openIsolatedCollection( ECollectionContextAllSongs ); |
659 TX_EXIT |
664 TX_EXIT |
660 } |
665 } |
661 |
666 |
662 /*! |
667 /*! |
663 Slot to be called when isolated collection is oppened. |
668 Slot to be called when isolated collection is oppened. |
664 */ |
669 */ |
665 void MpCollectionView::handleIsolatedCollectionOpened( MpMpxCollectionData* collectionData ) |
670 void MpCollectionView::handleIsolatedCollectionOpened( MpMpxCollectionData* collectionData ) |
666 { |
671 { |
667 TX_ENTRY |
672 TX_ENTRY |
668 if ( mActivated && !mOutstandingPopup ) { |
673 if ( mActivated ) { |
669 |
674 |
670 if (ECollectionContextPlaylistSongs == mCollectionContext) { |
675 if (ECollectionContextPlaylistSongs == mCollectionContext) { |
671 addToCurrentPlaylist( collectionData ); |
676 mMpPopupHandler->openAddToCurrentPlaylist( collectionData ); |
672 } |
677 } |
673 else if (ECollectionContextPlaylists == mCollectionContext) { |
678 else if (ECollectionContextPlaylists == mCollectionContext) { |
674 createNewPlaylist( collectionData ); |
679 mMpPopupHandler->openCreateNewPlaylist( collectionData ); |
675 } |
680 } |
676 } |
681 } |
677 //Playlist is saved asynchronosly by the default collection, it is OK to release now. |
682 TX_EXIT |
678 mMpEngine->releaseIsolatedCollection(); |
|
679 TX_EXIT |
|
680 } |
|
681 |
|
682 |
|
683 /*! |
|
684 Slot to be called to add items to current playlist. |
|
685 */ |
|
686 void MpCollectionView::addToCurrentPlaylist( MpMpxCollectionData* collectionData ) |
|
687 { |
|
688 MpCollectionDataModel *collectionDataModel; |
|
689 collectionDataModel = new MpCollectionDataModel( collectionData ); |
|
690 collectionDataModel->refreshModel(); |
|
691 QModelIndexList SelectedModelIndexes; |
|
692 bool ok; |
|
693 SelectedModelIndexes = getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), |
|
694 collectionDataModel, |
|
695 ok); |
|
696 |
|
697 if ( ok && SelectedModelIndexes.count() ) { |
|
698 QList<int> selection; |
|
699 for ( int i = 0; i < SelectedModelIndexes.size(); ++i ) { |
|
700 selection.append( SelectedModelIndexes.at( i ).row() ); |
|
701 } |
|
702 mMpEngine->saveToCurrentPlaylist( selection, collectionData ); |
|
703 } |
|
704 delete collectionDataModel; |
|
705 } |
|
706 |
|
707 /*! |
|
708 Slot to be called to add items to new playlist. |
|
709 */ |
|
710 void MpCollectionView::createNewPlaylist( MpMpxCollectionData* collectionData ) |
|
711 { |
|
712 MpCollectionDataModel *collectionDataModel; |
|
713 collectionDataModel = new MpCollectionDataModel( collectionData ); |
|
714 collectionDataModel->refreshModel(); |
|
715 |
|
716 QString newPlaylistName; |
|
717 bool ok; |
|
718 QStringList playlists; |
|
719 mMpEngine->findPlaylists( playlists ); |
|
720 ok = queryNewPlaylistName(newPlaylistName , playlists); |
|
721 if ( ok ) { |
|
722 QModelIndexList SelectedModelIndexes; |
|
723 SelectedModelIndexes = getModelIndexes( hbTrId( "txt_mus_title_select_songs" ), |
|
724 collectionDataModel, |
|
725 ok); |
|
726 QList<int> selection; |
|
727 if ( ok && SelectedModelIndexes.count() ) { |
|
728 for ( int i = 0; i < SelectedModelIndexes.size(); ++i ) { |
|
729 selection.append( SelectedModelIndexes.at( i ).row() ); |
|
730 } |
|
731 } |
|
732 //Creating Playlist even when there is no selection. |
|
733 mMpEngine->createPlaylist( newPlaylistName, selection, collectionData ); |
|
734 } |
|
735 delete collectionDataModel; |
|
736 } |
683 } |
737 |
684 |
738 /*! |
685 /*! |
739 Slot to be called to arrange songs in a playlist. |
686 Slot to be called to arrange songs in a playlist. |
740 */ |
687 */ |
741 void MpCollectionView::arrangeSongs( ) |
688 void MpCollectionView::arrangeSongs( ) |
742 { |
689 { |
743 HbListView *listView = new HbListView(); |
690 mMpPopupHandler->openArrangeSongs( mCollectionData ); |
744 listView->setItemRecycling(true); |
|
745 listView->setScrollingStyle( HbListView::PanOrFlick ); |
|
746 listView->setClampingStyle( HbListView::BounceBackClamping ); |
|
747 HbScrollBar *scrollbar = listView->verticalScrollBar(); |
|
748 scrollbar->show(); |
|
749 scrollbar->setInteractive(true); |
|
750 listView->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded); |
|
751 MpCollectionDataModel *model; |
|
752 //Ownership of the model is passed to the listView as a child object. |
|
753 model = new MpCollectionDataModel( mCollectionData, listView ); |
|
754 model->refreshModel(); |
|
755 connect( model, |
|
756 SIGNAL( orderChanged( int, int, int, int ) ), |
|
757 mMpEngine, |
|
758 SLOT( reorderPlaylist( int, int, int, int ) ) ); |
|
759 listView->setModel( model ); |
|
760 listView->setArrangeMode( true ); |
|
761 HbDialog *popup = new HbDialog(); |
|
762 popup->setAttribute( Qt::WA_DeleteOnClose ); |
|
763 popup->setDismissPolicy( HbPopup::NoDismiss ); |
|
764 popup->setTimeout( HbPopup::NoTimeout ); |
|
765 |
|
766 HbLabel *label = new HbLabel( hbTrId( "txt_mus_title_arrange" ) ); |
|
767 popup->setHeadingWidget( label ); |
|
768 popup->setContentWidget( listView ); |
|
769 popup->setPrimaryAction( new HbAction( hbTrId( "txt_common_button_ok" ), popup ) ); |
|
770 popup->setModal( true ); |
|
771 connect( popup, SIGNAL( aboutToClose() ), this, SLOT( outstandingPopupClosing() ) ); |
|
772 //Reopen the collection so the ordinals get fixed on the view list, if we |
|
773 //delete items the index will not match to the item on the collection. |
|
774 connect( popup, SIGNAL( aboutToClose() ), mMpEngine, SLOT( reopenCollection() ) ); |
|
775 setOutstandingPopup(popup); |
|
776 popup->show(); |
|
777 } |
691 } |
778 |
692 |
779 /*! |
693 /*! |
780 Slot to be called when an item is long pressed by the user. |
694 Slot to be called when an item is long pressed by the user. |
781 */ |
695 */ |
782 void MpCollectionView::openContextMenu( int index, const QPointF &coords ) |
696 void MpCollectionView::openContextMenu( int index, const QPointF &coords ) |
783 { |
697 { |
784 TX_ENTRY_ARGS( "index=" << index ); |
698 TX_ENTRY_ARGS( "index=" << index ); |
785 switch ( mViewMode ) { |
699 switch ( mViewMode ) { |
786 case MpCommon::DefaultView: |
700 case MpCommon::DefaultView: |
787 openDefaultViewContextMenu( index, coords ); |
701 mMpPopupHandler->openDefaultViewContextMenu( index, coords ); |
788 break; |
702 break; |
789 case MpCommon::FetchView: |
703 case MpCommon::FetchView: |
790 openFetchViewContextMenu( index, coords ); |
704 mMpPopupHandler->openFetchViewContextMenu( index, coords ); |
791 break; |
705 break; |
792 default: |
706 default: |
793 break; |
707 break; |
794 } |
708 } |
795 TX_EXIT |
709 TX_EXIT |
796 } |
710 } |
797 |
711 |
798 /*! |
712 /*! |
799 Slot to be called when a dialog is about to close. |
|
800 */ |
|
801 void MpCollectionView::outstandingPopupClosing() |
|
802 { |
|
803 HbPopup *popup = qobject_cast<HbPopup *>( sender() ); |
|
804 if ( popup ) { |
|
805 Q_ASSERT( popup != mOutstandingPopup ); |
|
806 mOutstandingPopup = 0; |
|
807 } |
|
808 } |
|
809 |
|
810 /*! |
|
811 Slot to be called when USB blocking status changes. |
713 Slot to be called when USB blocking status changes. |
812 */ |
714 */ |
813 void MpCollectionView::handleUsbBlocked( bool blocked ) |
715 void MpCollectionView::handleUsbBlocked( bool blocked ) |
814 { |
716 { |
815 TX_ENTRY_ARGS( "blocked=" << blocked ); |
717 TX_ENTRY_ARGS( "blocked=" << blocked ); |
816 mUsbBlocked = blocked; |
718 mUsbBlocked = blocked; |
817 |
719 |
818 if ( mActivated && mUsbBlocked && mOutstandingPopup ) { |
720 cancelOngoingOperation(); |
819 mOutstandingPopup->close(); |
|
820 mMpEngine->verifyUsbBlocking( true ); |
|
821 } |
|
822 |
721 |
823 updateMenu(); |
722 updateMenu(); |
824 if ( mCollectionContext == ECollectionContextPlaylistSongs ) { |
723 if ( mCollectionContext == ECollectionContextPlaylistSongs ) { |
825 updateToolBar(); |
724 updateToolBar(); |
826 } |
725 } |
852 if ( mActivationWaiting ) { |
745 if ( mActivationWaiting ) { |
853 mActivationWaiting = false; |
746 mActivationWaiting = false; |
854 activateView(); |
747 activateView(); |
855 } |
748 } |
856 else { |
749 else { |
|
750 cancelOngoingOperation(); |
|
751 |
857 //Update cache, even if collection is in background. |
752 //Update cache, even if collection is in background. |
858 //Library refreshing could be triggered at any point due USB connect./disconnect. |
753 //Library refreshing could be triggered at any point due USB/MMC events. |
859 mMpEngine->reopenCollection(); |
754 mMpEngine->reopenCollection(); |
860 } |
755 } |
861 TX_EXIT |
|
862 } |
|
863 |
|
864 /*! |
|
865 Default view context menu. |
|
866 */ |
|
867 void MpCollectionView::openDefaultViewContextMenu( int index, const QPointF &coords ) |
|
868 { |
|
869 HbMenu *contextMenu = 0; |
|
870 HbAction *action; |
|
871 switch ( mCollectionContext ) { |
|
872 case ECollectionContextAllSongs: |
|
873 case ECollectionContextAlbumSongs: |
|
874 contextMenu = new HbMenu(); |
|
875 action = contextMenu->addAction( hbTrId( "txt_common_menu_play_music" ) ); |
|
876 action->setObjectName( "play" ); |
|
877 action = contextMenu->addAction( hbTrId( "txt_mus_menu_add_to_playlist" ) ); |
|
878 action->setObjectName( "add" ); |
|
879 action->setEnabled( !mUsbBlocked ); |
|
880 action = contextMenu->addAction( hbTrId( "txt_common_menu_delete" ) ); |
|
881 action->setObjectName( "delete" ); |
|
882 action->setEnabled( !mUsbBlocked ); |
|
883 break; |
|
884 case ECollectionContextAlbums: |
|
885 contextMenu = new HbMenu(); |
|
886 action = contextMenu->addAction( hbTrId( "txt_common_menu_open" ) ); |
|
887 action->setObjectName( "open" ); |
|
888 action = contextMenu->addAction( hbTrId( "txt_mus_menu_add_to_playlist" ) ); |
|
889 action->setObjectName( "add" ); |
|
890 action->setEnabled( !mUsbBlocked ); |
|
891 action = contextMenu->addAction( hbTrId( "txt_common_menu_delete" ) ); |
|
892 action->setObjectName( "delete" ); |
|
893 action->setEnabled( !mUsbBlocked ); |
|
894 break; |
|
895 case ECollectionContextPlaylists: |
|
896 if ( !mCollectionData->isAutoPlaylist( index ) ) { |
|
897 contextMenu = new HbMenu(); |
|
898 action = contextMenu->addAction( hbTrId( "txt_common_menu_open" ) ); |
|
899 action->setObjectName( "open" ); |
|
900 action = contextMenu->addAction( hbTrId( "txt_common_menu_delete" ) ); |
|
901 action->setObjectName("delete"); |
|
902 action->setEnabled( !mUsbBlocked ); |
|
903 action = contextMenu->addAction( hbTrId( "txt_common_menu_rename_item" ) ); |
|
904 action->setObjectName( "rename playlist" ); |
|
905 action->setEnabled( !mUsbBlocked ); |
|
906 } |
|
907 break; |
|
908 case ECollectionContextPlaylistSongs: |
|
909 if ( !mCollectionData->isAutoPlaylist() ) { |
|
910 contextMenu = new HbMenu(); |
|
911 action = contextMenu->addAction( hbTrId( "txt_common_menu_play_music" ) ); |
|
912 action->setObjectName( "play" ); |
|
913 action = contextMenu->addAction( hbTrId( "txt_common_menu_remove" ) ); |
|
914 action->setObjectName( "delete" ); |
|
915 action->setEnabled( !mUsbBlocked ); |
|
916 } |
|
917 break; |
|
918 default: |
|
919 break; |
|
920 } |
|
921 |
|
922 if ( contextMenu ) { |
|
923 setOutstandingPopup( contextMenu ); |
|
924 HbAction *selectedAction = mActivated ? contextMenu->exec( coords ) : 0; |
|
925 setOutstandingPopup( 0 ); |
|
926 if ( selectedAction ) { |
|
927 QString objectName = selectedAction->objectName(); |
|
928 QList<int> selection; |
|
929 selection.append( index ); |
|
930 if ( objectName == "open" || objectName == "play" ) { |
|
931 QModelIndex modelIndex; |
|
932 modelIndex = mCollectionDataModel->index(index); |
|
933 qobject_cast<MpCollectionListContainer*>(mCollectionContainer)->itemActivated( modelIndex ); |
|
934 } |
|
935 else if ( !mMpEngine->verifyUsbBlocking( true ) ) { |
|
936 if ( objectName == "add" ) { |
|
937 launchAddToPlaylistDialog( selection ); |
|
938 } |
|
939 else if ( objectName == "delete" ) { |
|
940 requestDelete( selection ); |
|
941 } |
|
942 else if ( objectName == "rename playlist" ) { |
|
943 QString currentName; |
|
944 currentName = mCollectionData->itemData( index, MpMpxCollectionData::Title ); |
|
945 bool ok = false; |
|
946 QString newName; |
|
947 newName = getText( hbTrId("txt_mus_dialog_enter_name" ), currentName, ok ); |
|
948 if ( ok && ( currentName != newName ) ) { |
|
949 mMpEngine->renamePlaylist( newName, index ); |
|
950 } |
|
951 } |
|
952 } |
|
953 } |
|
954 } |
|
955 contextMenu->deleteLater(); |
|
956 TX_EXIT |
|
957 } |
|
958 |
|
959 /*! |
|
960 Fetch view context menu |
|
961 */ |
|
962 void MpCollectionView::openFetchViewContextMenu( int index, const QPointF &coords ) |
|
963 { |
|
964 TX_ENTRY_ARGS( "index=" << index ); |
|
965 |
|
966 HbMenu *contextMenu = 0; |
|
967 switch ( mCollectionContext ) { |
|
968 case ECollectionContextAllSongs: |
|
969 case ECollectionContextAlbumSongs: |
|
970 case ECollectionContextPlaylistSongs: |
|
971 case ECollectionContextGenreSongs: |
|
972 contextMenu = new HbMenu(); |
|
973 contextMenu->addAction( hbTrId("txt_common_menu_play_music") ); |
|
974 break; |
|
975 default: |
|
976 break; |
|
977 } |
|
978 |
|
979 if ( contextMenu ) { |
|
980 setOutstandingPopup( contextMenu ); |
|
981 if ( mActivated ? contextMenu->exec( coords ) : 0 ) { |
|
982 // Start the playback process. View will switch to playbackview. |
|
983 mMpEngine->previewItem( index ); |
|
984 } |
|
985 setOutstandingPopup( 0 ); |
|
986 } |
|
987 contextMenu->deleteLater(); |
|
988 TX_EXIT |
756 TX_EXIT |
989 } |
757 } |
990 |
758 |
991 /*! |
759 /*! |
992 \internal |
760 \internal |
1004 |
772 |
1005 // All Songs |
773 // All Songs |
1006 action = createToolBarAction( actionsGroup, "qtg_mono_songs_all" ); |
774 action = createToolBarAction( actionsGroup, "qtg_mono_songs_all" ); |
1007 connect( action, SIGNAL( triggered( bool ) ), this, SLOT( openSongs() ) ); |
775 connect( action, SIGNAL( triggered( bool ) ), this, SLOT( openSongs() ) ); |
1008 mMainToolBar->addAction( action ); |
776 mMainToolBar->addAction( action ); |
|
777 |
|
778 // Artists |
|
779 action = createToolBarAction( actionsGroup, "qtg_mono_artists" ); |
|
780 connect( action, SIGNAL( triggered( bool ) ), this, SLOT( openArtists() ) ); |
|
781 mMainToolBar->addAction( action ); |
1009 |
782 |
1010 // Albums |
783 // Albums |
1011 action = createToolBarAction( actionsGroup, "qtg_mono_artists_albums" ); |
784 action = createToolBarAction( actionsGroup, "qtg_mono_music_albums" ); |
1012 connect( action, SIGNAL( triggered( bool ) ), this, SLOT( openArtists() ) ); |
785 connect( action, SIGNAL( triggered( bool ) ), this, SLOT( openAlbums() ) ); |
1013 mMainToolBar->addAction( action ); |
786 mMainToolBar->addAction( action ); |
1014 |
787 |
1015 // Playlists |
788 // Playlists |
1016 action = createToolBarAction( actionsGroup, "qtg_mono_playlist" ); |
789 action = createToolBarAction( actionsGroup, "qtg_mono_playlist" ); |
1017 connect( action, SIGNAL( triggered( bool ) ), this, SLOT( openPlaylists() ) ); |
790 connect( action, SIGNAL( triggered( bool ) ), this, SLOT( openPlaylists() ) ); |
1160 connect( menuAction, SIGNAL( triggered() ), this, SLOT( refreshLibrary() ) ); |
937 connect( menuAction, SIGNAL( triggered() ), this, SLOT( refreshLibrary() ) ); |
1161 } |
938 } |
1162 else { |
939 else { |
1163 menuAction->setDisabled( true ); |
940 menuAction->setDisabled( true ); |
1164 } |
941 } |
|
942 |
|
943 connect( myMenu->addAction(hbTrId("txt_common_opt_exit")), SIGNAL(triggered()), this, SLOT(exit()) ); |
|
944 break; |
|
945 |
|
946 case ECollectionContextArtists: |
|
947 menuAction = myMenu->addAction( hbTrId( "txt_mus_opt_refresh_library" ) ); |
|
948 if ( !mUsbBlocked ) { |
|
949 connect( menuAction, SIGNAL( triggered() ), this, SLOT( refreshLibrary() ) ); |
|
950 } |
|
951 else { |
|
952 menuAction->setDisabled( true ); |
|
953 } |
1165 connect( myMenu->addAction(hbTrId("txt_common_opt_exit")), SIGNAL(triggered()), this, SLOT(exit()) ); |
954 connect( myMenu->addAction(hbTrId("txt_common_opt_exit")), SIGNAL(triggered()), this, SLOT(exit()) ); |
1166 break; |
955 break; |
1167 case ECollectionContextAlbums: |
956 case ECollectionContextAlbums: |
1168 //connect( myMenu->addAction( hbTrId( "txt_mus_opt_add_to_playlist" ) ), SIGNAL( triggered() ), this, SLOT( addToPlaylist() ) ); |
957 //connect( myMenu->addAction( hbTrId( "txt_mus_opt_add_to_playlist" ) ), SIGNAL( triggered() ), this, SLOT( addToPlaylist() ) ); |
1169 // Todo: View as coverflow |
958 // Todo: View as coverflow |
1338 return index; |
1131 return index; |
1339 } |
1132 } |
1340 |
1133 |
1341 /*! |
1134 /*! |
1342 \internal |
1135 \internal |
1343 Launches the 'Add to playlist' dialog. |
|
1344 */ |
|
1345 void MpCollectionView::launchAddToPlaylistDialog( QList<int> &selection ) |
|
1346 { |
|
1347 if (!mActivated) { |
|
1348 return; |
|
1349 } |
|
1350 QString newPlaylistName; |
|
1351 QStringList playlists; |
|
1352 mMpEngine->findPlaylists( playlists ); |
|
1353 HbListDialog dialog; |
|
1354 dialog.setStringItems( playlists ); |
|
1355 dialog.setSelectionMode( HbAbstractItemView::SingleSelection ); |
|
1356 dialog.setHeadingWidget(new HbLabel( hbTrId( "txt_mus_title_select_playlist" ) ) ); |
|
1357 dialog.setPrimaryAction(new HbAction( hbTrId( "txt_mus_button_new" ) ) ); |
|
1358 dialog.setSecondaryAction(new HbAction( hbTrId( "txt_common_button_cancel" ) ) ); |
|
1359 |
|
1360 forever { |
|
1361 if ( playlists.count() ) { |
|
1362 //There are saved playlists, query for a saved playlist or new. |
|
1363 setOutstandingPopup( &dialog ); |
|
1364 HbAction *selectedAction = mActivated ? dialog.exec() : 0; |
|
1365 setOutstandingPopup( 0 ); |
|
1366 if ( selectedAction == dialog.primaryAction() ) { |
|
1367 //User selected pimaryAction "new", fall trough to new playlyst query. |
|
1368 } |
|
1369 else if ( dialog.selectedItems().count() ) {//this only works for SingleSelection |
|
1370 // User selected existing playlist, add songs and exit the loop. |
|
1371 mMpEngine->saveToPlaylist( dialog.selectedItems().at( 0 ), selection ); |
|
1372 break; |
|
1373 } |
|
1374 else { |
|
1375 //Cancel was pressed or dialog was closed or never executed, exit the loop. |
|
1376 break; |
|
1377 } |
|
1378 } |
|
1379 //querying for a new playlist name. |
|
1380 if ( queryNewPlaylistName(newPlaylistName , playlists) ) { |
|
1381 // user selected a new playlist, save and exit the loop. |
|
1382 mMpEngine->createPlaylist( newPlaylistName, selection ); |
|
1383 break; |
|
1384 } |
|
1385 else if (!playlists.count()) { |
|
1386 // user decided to not provide a new name and there are no saved playlists, exit the loop |
|
1387 break; |
|
1388 } |
|
1389 // user decided to not provide a new name and there are saved playlists, back to the top. |
|
1390 } //forever |
|
1391 } |
|
1392 |
|
1393 /*! |
|
1394 \internal |
|
1395 starts a transition of the main container with a decoy snapshot. |
1136 starts a transition of the main container with a decoy snapshot. |
1396 */ |
1137 */ |
1397 void MpCollectionView::startContainerTransition( TCollectionContext contextFrom, TCollectionContext contextTo ) |
1138 void MpCollectionView::startContainerTransition( TCollectionContext contextFrom, TCollectionContext contextTo ) |
1398 { |
1139 { |
1399 if (contextFrom == contextTo) { |
1140 if (contextFrom == contextTo) { |
1459 |
1206 |
1460 } |
1207 } |
1461 |
1208 |
1462 /*! |
1209 /*! |
1463 \internal |
1210 \internal |
1464 request a delete operation always it has been confirmed. |
1211 Closes any active dialog or menu. |
1465 */ |
1212 */ |
1466 void MpCollectionView::requestDelete( QList<int> &selection ) |
1213 void MpCollectionView::cancelOngoingOperation() |
1467 { |
1214 { |
1468 bool confirmation( false ); |
1215 if ( mActivated ) { |
1469 // Todo: Use HbMessageBox::question when time-out removed from it |
1216 mMpPopupHandler->cancelOngoingPopup(); |
1470 HbMessageBox dialog( HbMessageBox::MessageTypeQuestion ); |
1217 menu()->close(); |
1471 |
1218 } |
1472 QString message; |
1219 } |
1473 HbAction *action = 0; |
1220 |
1474 |
|
1475 switch ( mCollectionContext ) { |
|
1476 case ECollectionContextAllSongs: |
|
1477 case ECollectionContextAlbumSongs: |
|
1478 message = hbTrId( "txt_mus_delete_song" ); |
|
1479 dialog.setText( message ); |
|
1480 dialog.setTimeout( HbPopup::NoTimeout ); |
|
1481 setOutstandingPopup( &dialog ); |
|
1482 action = mActivated ? dialog.exec() : 0; |
|
1483 setOutstandingPopup( 0 ); |
|
1484 if ( action && action == dialog.primaryAction() ) { |
|
1485 confirmation = true; |
|
1486 } |
|
1487 break; |
|
1488 case ECollectionContextAlbums: |
|
1489 message = hbTrId( "txt_mus_delete_album" ); |
|
1490 dialog.setText( message ); |
|
1491 dialog.setTimeout( HbPopup::NoTimeout ); |
|
1492 setOutstandingPopup( &dialog ); |
|
1493 action = mActivated ? dialog.exec() : 0; |
|
1494 setOutstandingPopup( 0 ); |
|
1495 if ( action && action == dialog.primaryAction() ) { |
|
1496 confirmation = true; |
|
1497 } |
|
1498 break; |
|
1499 case ECollectionContextPlaylists: |
|
1500 message = hbTrId( "txt_mus_delete_playlist" ); |
|
1501 dialog.setText( message ); |
|
1502 dialog.setTimeout( HbPopup::NoTimeout ); |
|
1503 setOutstandingPopup( &dialog ); |
|
1504 action = mActivated ? dialog.exec() : 0; |
|
1505 setOutstandingPopup( 0 ); |
|
1506 if ( action && action == dialog.primaryAction() ) { |
|
1507 confirmation = true; |
|
1508 } |
|
1509 break; |
|
1510 case ECollectionContextPlaylistSongs: |
|
1511 case ECollectionContextGenres: |
|
1512 case ECollectionContextGenreSongs: |
|
1513 confirmation = true; |
|
1514 break; |
|
1515 case ECollectionContextUnknown: |
|
1516 default: |
|
1517 // We shouldn't be here |
|
1518 TX_LOG_ARGS( "Invalid Collection Context:" << mCollectionContext ); |
|
1519 break; |
|
1520 } |
|
1521 |
|
1522 if ( confirmation ) { |
|
1523 mMpEngine->deleteSongs( selection ); |
|
1524 } |
|
1525 } |
|
1526 |
|
1527 /*! |
|
1528 \internal |
|
1529 Returns a list of itmes selected. |
|
1530 */ |
|
1531 QModelIndexList MpCollectionView::getModelIndexes( const QString &label, QAbstractItemModel* model, bool &ok ) |
|
1532 { |
|
1533 QModelIndexList result; |
|
1534 |
|
1535 if ( !mActivated ) { |
|
1536 ok = false; |
|
1537 return result; |
|
1538 } |
|
1539 |
|
1540 HbListDialog *dlg = new HbListDialog(); |
|
1541 dlg->setHeadingWidget( new HbLabel( label ) ); |
|
1542 dlg->setSelectionMode( HbAbstractItemView::MultiSelection ); |
|
1543 dlg->setModel( model ); |
|
1544 setOutstandingPopup( dlg ); |
|
1545 HbAction* action = mActivated ? dlg->exec() : 0; |
|
1546 setOutstandingPopup( 0 ); |
|
1547 if( action == dlg->primaryAction() ){ //OK was pressed |
|
1548 ok = true; |
|
1549 result = dlg->selectedModelIndexes(); |
|
1550 } |
|
1551 else{ //Cancel was pressed or dialog was closed or never executed. |
|
1552 ok = false; |
|
1553 } |
|
1554 dlg->setModel( 0 ); |
|
1555 delete dlg; |
|
1556 return result; |
|
1557 } |
|
1558 |
|
1559 /*! |
|
1560 \internal |
|
1561 Returns a string from user input. |
|
1562 */ |
|
1563 QString MpCollectionView::getText( const QString &label,const QString &text, |
|
1564 bool &ok ) |
|
1565 { |
|
1566 |
|
1567 QString result; |
|
1568 |
|
1569 if ( !mActivated ) { |
|
1570 ok = false; |
|
1571 return result; |
|
1572 } |
|
1573 |
|
1574 HbInputDialog *dlg = new HbInputDialog(); |
|
1575 dlg->setPromptText( label ); |
|
1576 dlg->setInputMode( HbInputDialog::TextInput ); |
|
1577 dlg->setValue( text ); |
|
1578 setOutstandingPopup( dlg ); |
|
1579 HbAction* action = mActivated ? dlg->exec() : 0; |
|
1580 setOutstandingPopup( 0 ); |
|
1581 if( action == dlg->primaryAction() ) { //OK was pressed |
|
1582 ok = true; |
|
1583 result = dlg->value().toString(); |
|
1584 } else { //Cancel was pressed or dialog was closed or never executed. |
|
1585 ok = false; |
|
1586 } |
|
1587 delete dlg; |
|
1588 return result; |
|
1589 } |
|
1590 |
|
1591 /*! |
|
1592 \internal |
|
1593 sets \a popup as the current outstanding popup and cancels any otstanding popup. |
|
1594 */ |
|
1595 void MpCollectionView::setOutstandingPopup( HbPopup *popup ) |
|
1596 { |
|
1597 if ( mOutstandingPopup ) { |
|
1598 mOutstandingPopup->close(); |
|
1599 } |
|
1600 mOutstandingPopup = popup; |
|
1601 } |
|
1602 |
|
1603 /*! |
|
1604 \internal |
|
1605 sets \a newPlaylistName with imput name from the user, uses \a playlists to |
|
1606 generate a suggested playlist name, retrns true if the user confirmed the query. |
|
1607 */ |
|
1608 bool MpCollectionView::queryNewPlaylistName(QString &newPlaylistName , const QStringList &playlists ) |
|
1609 { |
|
1610 bool ret= false; |
|
1611 if (!mActivated) { |
|
1612 return ret; |
|
1613 } |
|
1614 int i = 0; |
|
1615 for ( ; |
|
1616 playlists.contains( hbTrId( "txt_mus_dialog_enter_name_entry_playlist_l1" ).arg( i ) ) ; |
|
1617 i++ ) {}; |
|
1618 QString suggestedPlaylistName = hbTrId( "txt_mus_dialog_enter_name_entry_playlist_l1" ).arg( i ); |
|
1619 QString suggestedText; |
|
1620 bool ok = false; |
|
1621 suggestedText = getText( hbTrId("txt_mus_dialog_enter_name" ), suggestedPlaylistName, ok); |
|
1622 if ( ok ) { |
|
1623 newPlaylistName = suggestedText; |
|
1624 ret = true; |
|
1625 } |
|
1626 return ret; |
|
1627 } |
|
1628 |
|