Commit 100d4cfb authored by Alexander Stippich's avatar Alexander Stippich
Browse files

reuse the persistent state to restore playlist and cleanup

parent 310cf118
......@@ -568,10 +568,10 @@ void MediaPlayListTest::undoClearPlayListCase()
QCOMPARE(rowsInsertedSpy.count(), 3);
QCOMPARE(tracksCountChangedSpy.count(), 4);
QCOMPARE(persistentStateChangedSpy.count(), 4);
QCOMPARE(dataChangedSpy.count(), 8);
QCOMPARE(newTrackByNameInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.count(), 7);
QCOMPARE(currentTrackChangedSpy.count(), 3);
QCOMPARE(dataChangedSpy.count(), 13);
QCOMPARE(newTrackByNameInListSpy.count(), 6);
QCOMPARE(newEntryInListSpy.count(), 1);
QCOMPARE(currentTrackChangedSpy.count(), 4);
QCOMPARE(displayUndoNotificationSpy.count(), 1);
QCOMPARE(myPlayList.rowCount(), 6);
......@@ -802,10 +802,10 @@ void MediaPlayListTest::undoReplacePlayListCase()
QCOMPARE(rowsInsertedSpy.count(), 5);
QCOMPARE(tracksCountChangedSpy.count(), 7);
QCOMPARE(persistentStateChangedSpy.count(), 7);
QCOMPARE(dataChangedSpy.count(), 9);
QCOMPARE(newTrackByNameInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.count(), 8);
QCOMPARE(currentTrackChangedSpy.count(), 5);
QCOMPARE(dataChangedSpy.count(), 14);
QCOMPARE(newTrackByNameInListSpy.count(), 6);
QCOMPARE(newEntryInListSpy.count(), 2);
QCOMPARE(currentTrackChangedSpy.count(), 6);
QCOMPARE(displayUndoNotificationSpy.count(), 2);
QCOMPARE(myPlayList.rowCount(), 6);
......
......@@ -56,9 +56,10 @@ public:
QList<int> mRandomPositions = {0, 0, 0};
QVariantMap mPersistentSettingsForUndo;
};
MediaPlayList::MediaPlayList(QObject *parent) : QAbstractListModel(parent), d(new MediaPlayListPrivate), dOld(new MediaPlayListPrivate)
MediaPlayList::MediaPlayList(QObject *parent) : QAbstractListModel(parent), d(new MediaPlayListPrivate)
{
connect(&d->mLoadPlaylist, &QMediaPlaylist::loaded, this, &MediaPlayList::loadPlayListLoaded);
connect(&d->mLoadPlaylist, &QMediaPlaylist::loadFailed, this, &MediaPlayList::loadPlayListLoadFailed);
......@@ -554,9 +555,9 @@ void MediaPlayList::clearPlayList(bool prepareUndo)
return;
}
if(prepareUndo){
if (prepareUndo) {
Q_EMIT clearPlayListPlayer();
this->copyD();
d->mPersistentSettingsForUndo = persistentState();
}
beginRemoveRows({}, 0, d->mData.count() - 1);
......@@ -583,60 +584,10 @@ void MediaPlayList::undoClearPlayList()
{
clearPlayList(false);
beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + dOld->mData.size() - 1);
for (auto &newTrack : dOld->mData) {
d->mData.push_back(newTrack);
d->mTrackData.push_back({});
if (ElisaUtils::FileName == newTrack.mEntryType && newTrack.mTrackUrl.isValid()) {
auto entryURL = newTrack.mTrackUrl.toUrl();
if (entryURL.isLocalFile()) {
auto entryString = entryURL.toLocalFile();
QFileInfo newTrackFile(entryString);
if (newTrackFile.exists()) {
d->mData.last().mIsValid = true;
}
Q_EMIT newEntryInList(0, entryString, newTrack.mEntryType);
}
}
else if(ElisaUtils::Artist == newTrack.mEntryType){
Q_EMIT newEntryInList(0, newTrack.mArtist.toString(), newTrack.mEntryType);
}
else{
Q_EMIT newEntryInList(newTrack.mId, newTrack.mTitle.toString(), newTrack.mEntryType);
}
}
endInsertRows();
d->mCurrentPlayListPosition = dOld->mCurrentPlayListPosition;
d->mRandomPlay = dOld->mRandomPlay;
d->mRepeatPlay = dOld->mRepeatPlay;
auto candidateTrack = index(dOld->mCurrentPlayListPosition, 0);
if (candidateTrack.isValid() && candidateTrack.data(ColumnsRoles::IsValidRole).toBool()) {
d->mCurrentTrack = candidateTrack;
notifyCurrentTrackChanged();
}
Q_EMIT tracksCountChanged();
Q_EMIT remainingTracksChanged();
Q_EMIT persistentStateChanged();
Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::IsPlayingRole});
setPersistentState(d->mPersistentSettingsForUndo);
Q_EMIT undoClearPlayListPlayer();
}
void MediaPlayList::copyD()
{
dOld->mData = d->mData;
dOld->mTrackData = d->mTrackData;
dOld->mCurrentTrack = d->mCurrentTrack;
dOld->mCurrentPlayListPosition = d->mCurrentPlayListPosition;
dOld->mRandomPlay = d->mRandomPlay;
dOld->mRepeatPlay = d->mRepeatPlay;
}
void MediaPlayList::loadPlaylist(const QUrl &fileName)
{
d->mLoadPlaylist.clear();
......
......@@ -308,11 +308,7 @@ private:
void enqueueMultipleEntries(const ElisaUtils::EntryDataList &entriesData, ElisaUtils::PlayListEntryType type);
void copyD();
std::unique_ptr<MediaPlayListPrivate> d;
std::unique_ptr<MediaPlayListPrivate> dOld;
};
class MediaPlayListEntry
......
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