Commit dfa4cb9a authored by stef lep's avatar stef lep Committed by Matthieu Gallien

bug-414771 seek to origin before going to previous track

parent c94039e2
...@@ -1960,7 +1960,7 @@ void MediaPlayListProxyModelTest::testShuffleMode() ...@@ -1960,7 +1960,7 @@ void MediaPlayListProxyModelTest::testShuffleMode()
QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(repeatPlayChangedSpy.count(), 1);
QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0);
myPlayListProxyModel.skipPreviousTrack(); myPlayListProxyModel.skipPreviousTrack(0);
QCOMPARE(currentTrackChangedSpy.count(), 5); QCOMPARE(currentTrackChangedSpy.count(), 5);
QCOMPARE(shufflePlayListChangedSpy.count(), 1); QCOMPARE(shufflePlayListChangedSpy.count(), 1);
...@@ -3138,7 +3138,7 @@ void MediaPlayListProxyModelTest::testBringUpAndSkipPreviousAndContinueCase() ...@@ -3138,7 +3138,7 @@ void MediaPlayListProxyModelTest::testBringUpAndSkipPreviousAndContinueCase()
QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(5, 0))); QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(5, 0)));
myPlayListProxyModel.skipPreviousTrack(); myPlayListProxyModel.skipPreviousTrack(0);
QCOMPARE(currentTrackChangedSpy.count(), 7); QCOMPARE(currentTrackChangedSpy.count(), 7);
QCOMPARE(shufflePlayListChangedSpy.count(), 0); QCOMPARE(shufflePlayListChangedSpy.count(), 0);
...@@ -3147,7 +3147,7 @@ void MediaPlayListProxyModelTest::testBringUpAndSkipPreviousAndContinueCase() ...@@ -3147,7 +3147,7 @@ void MediaPlayListProxyModelTest::testBringUpAndSkipPreviousAndContinueCase()
QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(4, 0))); QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(4, 0)));
myPlayListProxyModel.skipPreviousTrack(); myPlayListProxyModel.skipPreviousTrack(0);
QCOMPARE(currentTrackChangedSpy.count(), 8); QCOMPARE(currentTrackChangedSpy.count(), 8);
QCOMPARE(shufflePlayListChangedSpy.count(), 0); QCOMPARE(shufflePlayListChangedSpy.count(), 0);
...@@ -3156,7 +3156,7 @@ void MediaPlayListProxyModelTest::testBringUpAndSkipPreviousAndContinueCase() ...@@ -3156,7 +3156,7 @@ void MediaPlayListProxyModelTest::testBringUpAndSkipPreviousAndContinueCase()
QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(3, 0))); QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(3, 0)));
myPlayListProxyModel.skipPreviousTrack(); myPlayListProxyModel.skipPreviousTrack(0);
QCOMPARE(currentTrackChangedSpy.count(), 9); QCOMPARE(currentTrackChangedSpy.count(), 9);
QCOMPARE(shufflePlayListChangedSpy.count(), 0); QCOMPARE(shufflePlayListChangedSpy.count(), 0);
...@@ -3165,7 +3165,7 @@ void MediaPlayListProxyModelTest::testBringUpAndSkipPreviousAndContinueCase() ...@@ -3165,7 +3165,7 @@ void MediaPlayListProxyModelTest::testBringUpAndSkipPreviousAndContinueCase()
QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(2, 0))); QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(2, 0)));
myPlayListProxyModel.skipPreviousTrack(); myPlayListProxyModel.skipPreviousTrack(0);
QCOMPARE(currentTrackChangedSpy.count(), 10); QCOMPARE(currentTrackChangedSpy.count(), 10);
QCOMPARE(shufflePlayListChangedSpy.count(), 0); QCOMPARE(shufflePlayListChangedSpy.count(), 0);
...@@ -3174,7 +3174,7 @@ void MediaPlayListProxyModelTest::testBringUpAndSkipPreviousAndContinueCase() ...@@ -3174,7 +3174,7 @@ void MediaPlayListProxyModelTest::testBringUpAndSkipPreviousAndContinueCase()
QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(1, 0))); QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(1, 0)));
myPlayListProxyModel.skipPreviousTrack(); myPlayListProxyModel.skipPreviousTrack(0);
QCOMPARE(currentTrackChangedSpy.count(), 11); QCOMPARE(currentTrackChangedSpy.count(), 11);
QCOMPARE(shufflePlayListChangedSpy.count(), 0); QCOMPARE(shufflePlayListChangedSpy.count(), 0);
...@@ -3183,7 +3183,7 @@ void MediaPlayListProxyModelTest::testBringUpAndSkipPreviousAndContinueCase() ...@@ -3183,7 +3183,7 @@ void MediaPlayListProxyModelTest::testBringUpAndSkipPreviousAndContinueCase()
QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(0, 0))); QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(0, 0)));
myPlayListProxyModel.skipPreviousTrack(); myPlayListProxyModel.skipPreviousTrack(0);
QCOMPARE(currentTrackChangedSpy.count(), 12); QCOMPARE(currentTrackChangedSpy.count(), 12);
QCOMPARE(shufflePlayListChangedSpy.count(), 0); QCOMPARE(shufflePlayListChangedSpy.count(), 0);
...@@ -3442,7 +3442,7 @@ void MediaPlayListProxyModelTest::testBringUpAndSkipPreviousCase() ...@@ -3442,7 +3442,7 @@ void MediaPlayListProxyModelTest::testBringUpAndSkipPreviousCase()
QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(1, 0))); QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(1, 0)));
myPlayListProxyModel.skipPreviousTrack(); myPlayListProxyModel.skipPreviousTrack(0);
QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(currentTrackChangedSpy.count(), 3);
QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0);
...@@ -3450,6 +3450,81 @@ void MediaPlayListProxyModelTest::testBringUpAndSkipPreviousCase() ...@@ -3450,6 +3450,81 @@ void MediaPlayListProxyModelTest::testBringUpAndSkipPreviousCase()
QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(0, 0))); QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(0, 0)));
} }
void MediaPlayListProxyModelTest::testBringUpAndSkipPreviousWithSeekCase()
{
MediaPlayList myPlayList;
QAbstractItemModelTester testModel(&myPlayList);
MediaPlayListProxyModel myPlayListProxyModel;
myPlayListProxyModel.setPlayListModel(&myPlayList);
QAbstractItemModelTester testProxyModel(&myPlayListProxyModel);
DatabaseInterface myDatabaseContent;
TracksListener myListener(&myDatabaseContent);
QSignalSpy currentTrackChangedSpy(&myPlayListProxyModel, &MediaPlayListProxyModel::currentTrackChanged);
QSignalSpy playListFinishedSpy(&myPlayListProxyModel, &MediaPlayListProxyModel::playListFinished);
QSignalSpy trackSeekedSpy(&myPlayListProxyModel, &MediaPlayListProxyModel::seek);
myDatabaseContent.init(QStringLiteral("testDbDirectContent"));
connect(&myListener, &TracksListener::trackHasChanged,
&myPlayList, &MediaPlayList::trackChanged,
Qt::QueuedConnection);
connect(&myListener, &TracksListener::tracksListAdded,
&myPlayList, &MediaPlayList::tracksListAdded,
Qt::QueuedConnection);
connect(&myPlayList, &MediaPlayList::newTrackByNameInList,
&myListener, &TracksListener::trackByNameInList,
Qt::QueuedConnection);
connect(&myPlayList, &MediaPlayList::newEntryInList,
&myListener, &TracksListener::newEntryInList,
Qt::QueuedConnection);
connect(&myPlayList, &MediaPlayList::newUrlInList,
&myListener, &TracksListener::newUrlInList,
Qt::QueuedConnection);
connect(&myDatabaseContent, &DatabaseInterface::tracksAdded,
&myListener, &TracksListener::tracksAdded);
myDatabaseContent.insertTracksList(mNewTracks, mNewCovers);
QCOMPARE(currentTrackChangedSpy.count(), 0);
QCOMPARE(playListFinishedSpy.count(), 0);
myPlayListProxyModel.enqueue({{{{DataTypes::ElementTypeRole, ElisaUtils::Track},
{DataTypes::DatabaseIdRole, myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1)}},
QStringLiteral("track1"), {}}}, {}, {});
myPlayListProxyModel.enqueue({{{{DataTypes::ElementTypeRole, ElisaUtils::Track},
{DataTypes::DatabaseIdRole, myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album1"), 3, 3)}},
QStringLiteral("track3"), {}}}, {}, {});
QCOMPARE(currentTrackChangedSpy.count(), 1);
QCOMPARE(playListFinishedSpy.count(), 0);
QCOMPARE(trackSeekedSpy.count(), 0);
QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(0, 0)));
myPlayListProxyModel.skipNextTrack();
QCOMPARE(currentTrackChangedSpy.count(), 2);
QCOMPARE(playListFinishedSpy.count(), 0);
QCOMPARE(trackSeekedSpy.count(), 0);
QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(1, 0)));
myPlayListProxyModel.skipPreviousTrack(10000);
QCOMPARE(currentTrackChangedSpy.count(), 2);
QCOMPARE(playListFinishedSpy.count(), 0);
QCOMPARE(trackSeekedSpy.count(), 1);
myPlayListProxyModel.skipPreviousTrack(0);
QCOMPARE(currentTrackChangedSpy.count(), 3);
QCOMPARE(playListFinishedSpy.count(), 0);
QCOMPARE(trackSeekedSpy.count(), 1);
QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(0, 0)));
}
void MediaPlayListProxyModelTest::testRemoveSelection() void MediaPlayListProxyModelTest::testRemoveSelection()
{ {
MediaPlayList myPlayList; MediaPlayList myPlayList;
......
...@@ -68,6 +68,8 @@ private Q_SLOTS: ...@@ -68,6 +68,8 @@ private Q_SLOTS:
void testBringUpAndSkipPreviousCase(); void testBringUpAndSkipPreviousCase();
void testBringUpAndSkipPreviousWithSeekCase();
void testBringUpAndRemoveCase(); void testBringUpAndRemoveCase();
void testBringUpAndRemoveLastCase(); void testBringUpAndRemoveLastCase();
......
...@@ -411,7 +411,7 @@ void ElisaApplication::initializePlayer() ...@@ -411,7 +411,7 @@ void ElisaApplication::initializePlayer()
QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::currentTrackChanged, d->mAudioControl.get(), &ManageAudioPlayer::setCurrentTrack); QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::currentTrackChanged, d->mAudioControl.get(), &ManageAudioPlayer::setCurrentTrack);
QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::clearPlayListPlayer, d->mAudioControl.get(), &ManageAudioPlayer::saveForUndoClearPlaylist); QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::clearPlayListPlayer, d->mAudioControl.get(), &ManageAudioPlayer::saveForUndoClearPlaylist);
QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::undoClearPlayListPlayer, d->mAudioControl.get(), &ManageAudioPlayer::restoreForUndoClearPlaylist); QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::undoClearPlayListPlayer, d->mAudioControl.get(), &ManageAudioPlayer::restoreForUndoClearPlaylist);
QObject::connect(d->mMediaPlayListProxyModel.get(), &MediaPlayListProxyModel::seek, d->mAudioWrapper.get(), &AudioWrapper::seek);
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::playbackStateChanged, QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::playbackStateChanged,
d->mAudioControl.get(), &ManageAudioPlayer::setPlayerPlaybackState); d->mAudioControl.get(), &ManageAudioPlayer::setPlayerPlaybackState);
......
...@@ -527,12 +527,17 @@ void MediaPlayListProxyModel::skipNextTrack() ...@@ -527,12 +527,17 @@ void MediaPlayListProxyModel::skipNextTrack()
notifyCurrentTrackChanged(); notifyCurrentTrackChanged();
} }
void MediaPlayListProxyModel::skipPreviousTrack() void MediaPlayListProxyModel::skipPreviousTrack(qint64 position)
{ {
if (!d->mCurrentTrack.isValid()) { if (!d->mCurrentTrack.isValid()) {
return; return;
} }
if (position > mSeekToBeginningDelay) {
emit seek(0);
return;
}
if (d->mCurrentTrack.row() == 0) { if (d->mCurrentTrack.row() == 0) {
if (d->mRepeatPlay) { if (d->mRepeatPlay) {
d->mCurrentTrack = index(rowCount() - 1, 0); d->mCurrentTrack = index(rowCount() - 1, 0);
......
...@@ -112,6 +112,9 @@ public: ...@@ -112,6 +112,9 @@ public:
QVariantMap persistentState() const; QVariantMap persistentState() const;
int mSeekToBeginningDelay = 2000;
public Q_SLOTS: public Q_SLOTS:
void enqueue(const QUrl &entryUrl, void enqueue(const QUrl &entryUrl,
...@@ -135,7 +138,7 @@ public Q_SLOTS: ...@@ -135,7 +138,7 @@ public Q_SLOTS:
void skipNextTrack(); void skipNextTrack();
void skipPreviousTrack(); void skipPreviousTrack(qint64 position);
void switchTo(int row); void switchTo(int row);
...@@ -202,6 +205,8 @@ Q_SIGNALS: ...@@ -202,6 +205,8 @@ Q_SIGNALS:
void hideUndoNotification(); void hideUndoNotification();
void seek(qint64 position);
private Q_SLOTS: private Q_SLOTS:
void sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end); void sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
......
...@@ -133,7 +133,7 @@ void MediaPlayer2Player::Previous() ...@@ -133,7 +133,7 @@ void MediaPlayer2Player::Previous()
emit previous(); emit previous();
if (m_playListControler) { if (m_playListControler) {
m_playListControler->skipPreviousTrack(); m_playListControler->skipPreviousTrack(m_audioPlayer->position());
} }
} }
......
...@@ -209,7 +209,7 @@ ApplicationWindow { ...@@ -209,7 +209,7 @@ ApplicationWindow {
playerControl.onPlay: ElisaApplication.audioControl.playPause() playerControl.onPlay: ElisaApplication.audioControl.playPause()
playerControl.onPause: ElisaApplication.audioControl.playPause() playerControl.onPause: ElisaApplication.audioControl.playPause()
playerControl.onPlayPrevious: ElisaApplication.mediaPlayListProxyModel.skipPreviousTrack() playerControl.onPlayPrevious: ElisaApplication.mediaPlayListProxyModel.skipPreviousTrack(ElisaApplication.audioPlayer.position)
playerControl.onPlayNext: ElisaApplication.mediaPlayListProxyModel.skipNextTrack() playerControl.onPlayNext: ElisaApplication.mediaPlayListProxyModel.skipNextTrack()
playerControl.isMaximized: persistentSettings.headerBarIsMaximized playerControl.isMaximized: persistentSettings.headerBarIsMaximized
......
...@@ -52,7 +52,7 @@ Item { ...@@ -52,7 +52,7 @@ Item {
ThumbnailToolButton { ThumbnailToolButton {
iconSource: Qt.resolvedUrl(LayoutMirroring.enabled ? elisaTheme.skipForwardIcon : elisaTheme.skipBackwardIcon) iconSource: Qt.resolvedUrl(LayoutMirroring.enabled ? elisaTheme.skipForwardIcon : elisaTheme.skipBackwardIcon)
onClicked: playListModel.skipPreviousTrack() onClicked: playListModel.skipPreviousTrack(player.position)
enabled: manageMediaPlayerControl.skipBackwardControlEnabled enabled: manageMediaPlayerControl.skipBackwardControlEnabled
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment