Commit 6b2b9b03 authored by Alexander Stippich's avatar Alexander Stippich
Browse files

cleanup and simplify mediaplaylist

parent c692d8af
......@@ -1316,7 +1316,14 @@ void MediaPlayListTest::testHasHeaderWithRestore()
connect(&myDatabaseContent, &DatabaseInterface::tracksAdded,
&myListener, &TracksListener::tracksAdded);
myPlayList.enqueueRestoredEntry({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1});
QVariantList entries;
myPlayList.enqueueRestoredEntries(
QVariantList({QStringList({{},QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("1"), QStringLiteral("1"),{}}),
QStringList({{},QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), QStringLiteral("1"), QStringLiteral("1"),{}}),
QStringList({{},QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("2"), QStringLiteral("1"),{}}),
QStringList({{},QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("3"), QStringLiteral("1"),{}})
}));
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
......@@ -1324,63 +1331,7 @@ void MediaPlayListTest::testHasHeaderWithRestore()
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 1);
QCOMPARE(persistentStateChangedSpy.count(), 1);
QCOMPARE(dataChangedSpy.count(), 1);
QCOMPARE(newTrackByNameInListSpy.count(), 1);
QCOMPARE(newEntryInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.wait(50), false);
myPlayList.enqueueRestoredEntry({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1});
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2);
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 2);
QCOMPARE(persistentStateChangedSpy.count(), 2);
QCOMPARE(dataChangedSpy.count(), 2);
QCOMPARE(newTrackByNameInListSpy.count(), 2);
QCOMPARE(newEntryInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.wait(50), false);
myPlayList.enqueueRestoredEntry({QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), 2, 1});
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3);
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 3);
QCOMPARE(persistentStateChangedSpy.count(), 3);
QCOMPARE(dataChangedSpy.count(), 3);
QCOMPARE(newTrackByNameInListSpy.count(), 3);
QCOMPARE(newEntryInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.wait(50), false);
myPlayList.enqueueRestoredEntry({QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), 3, 1});
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4);
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 4);
QCOMPARE(persistentStateChangedSpy.count(), 4);
QCOMPARE(dataChangedSpy.count(), 4);
QCOMPARE(newTrackByNameInListSpy.count(), 4);
QCOMPARE(newEntryInListSpy.count(), 0);
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4);
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 4);
QCOMPARE(persistentStateChangedSpy.count(), 4);
QCOMPARE(persistentStateChangedSpy.count(), 0);
QCOMPARE(dataChangedSpy.count(), 4);
QCOMPARE(newTrackByNameInListSpy.count(), 4);
QCOMPARE(newEntryInListSpy.count(), 0);
......@@ -1393,11 +1344,11 @@ void MediaPlayListTest::testHasHeaderWithRestore()
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4);
QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1);
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 4);
QCOMPARE(persistentStateChangedSpy.count(), 4);
QCOMPARE(rowsInsertedSpy.count(), 1);
QCOMPARE(persistentStateChangedSpy.count(), 0);
QCOMPARE(dataChangedSpy.count(), 8);
QCOMPARE(newTrackByNameInListSpy.count(), 4);
QCOMPARE(newEntryInListSpy.count(), 0);
......@@ -2885,7 +2836,12 @@ void MediaPlayListTest::restoreMultipleIdenticalTracks()
connect(&myDatabaseContent, &DatabaseInterface::tracksAdded,
&myListener, &TracksListener::tracksAdded);
myPlayList.enqueueRestoredEntry({QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3});
myPlayList.enqueueRestoredEntries(
QVariantList({QStringList({{},QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), QStringLiteral("3"), QStringLiteral("3"),{}}),
QStringList({{},QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), QStringLiteral("3"), QStringLiteral("3"),{}}),
QStringList({{},QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), QStringLiteral("3"), QStringLiteral("3"),{}}),
QStringList({{},QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), QStringLiteral("3"), QStringLiteral("3"),{}})
}));
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
......@@ -2893,72 +2849,22 @@ void MediaPlayListTest::restoreMultipleIdenticalTracks()
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 1);
QCOMPARE(persistentStateChangedSpy.count(), 1);
QCOMPARE(dataChangedSpy.count(), 1);
QCOMPARE(newTrackByNameInListSpy.count(), 1);
QCOMPARE(newEntryInListSpy.count(), 0);
myPlayList.enqueueRestoredEntry({QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3});
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2);
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 2);
QCOMPARE(persistentStateChangedSpy.count(), 2);
QCOMPARE(dataChangedSpy.count(), 2);
QCOMPARE(newTrackByNameInListSpy.count(), 2);
QCOMPARE(newEntryInListSpy.count(), 0);
myPlayList.enqueueRestoredEntry({QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3});
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3);
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 3);
QCOMPARE(persistentStateChangedSpy.count(), 3);
QCOMPARE(dataChangedSpy.count(), 3);
QCOMPARE(newTrackByNameInListSpy.count(), 3);
QCOMPARE(newEntryInListSpy.count(), 0);
myPlayList.enqueueRestoredEntry({QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3});
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4);
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 4);
QCOMPARE(persistentStateChangedSpy.count(), 4);
QCOMPARE(persistentStateChangedSpy.count(), 0);
QCOMPARE(dataChangedSpy.count(), 4);
QCOMPARE(newTrackByNameInListSpy.count(), 4);
QCOMPARE(newEntryInListSpy.count(), 0);
myDatabaseContent.insertTracksList(mNewTracks, mNewCovers);
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4);
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 4);
QCOMPARE(persistentStateChangedSpy.count(), 4);
QCOMPARE(dataChangedSpy.count(), 4);
QCOMPARE(newTrackByNameInListSpy.count(), 4);
QCOMPARE(newEntryInListSpy.count(), 0);
QCOMPARE(dataChangedSpy.wait(), true);
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4);
QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1);
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 4);
QCOMPARE(persistentStateChangedSpy.count(), 4);
QCOMPARE(rowsInsertedSpy.count(), 1);
QCOMPARE(persistentStateChangedSpy.count(), 0);
QCOMPARE(dataChangedSpy.count(), 8);
QCOMPARE(newTrackByNameInListSpy.count(), 4);
QCOMPARE(newEntryInListSpy.count(), 0);
......@@ -3087,12 +2993,7 @@ void MediaPlayListTest::restoreTrackWithoutAlbum()
QCOMPARE(newTrackByNameInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.count(), 0);
auto newEntry = MediaPlayListEntry{};
newEntry.mTitle = QStringLiteral("track19");
newEntry.mArtist = QStringLiteral("artist2");
myPlayList.enqueueRestoredEntry(newEntry);
myPlayList.enqueueRestoredEntries(QVariantList({QStringList({QStringLiteral("0"), QStringLiteral("track19"), QStringLiteral("artist2"), {}, {}, {}, QString::number(ElisaUtils::PlayListEntryType::Unknown)})}));
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
......@@ -3100,7 +3001,7 @@ void MediaPlayListTest::restoreTrackWithoutAlbum()
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 1);
QCOMPARE(persistentStateChangedSpy.count(), 1);
QCOMPARE(persistentStateChangedSpy.count(), 0);
QCOMPARE(dataChangedSpy.count(), 1);
QCOMPARE(newTrackByNameInListSpy.count(), 1);
QCOMPARE(newEntryInListSpy.count(), 0);
......@@ -3113,7 +3014,7 @@ void MediaPlayListTest::restoreTrackWithoutAlbum()
QCOMPARE(rowsRemovedSpy.count(), 0);
QCOMPARE(rowsMovedSpy.count(), 0);
QCOMPARE(rowsInsertedSpy.count(), 1);
QCOMPARE(persistentStateChangedSpy.count(), 1);
QCOMPARE(persistentStateChangedSpy.count(), 0);
QCOMPARE(dataChangedSpy.count(), 2);
QCOMPARE(newTrackByNameInListSpy.count(), 1);
QCOMPARE(newEntryInListSpy.count(), 0);
......@@ -3661,11 +3562,11 @@ void MediaPlayListTest::testSavePersistentState()
QCOMPARE(newEntryInListSpySave.count(), 3);
QCOMPARE(rowsAboutToBeRemovedSpyRead.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpyRead.count(), 0);
QCOMPARE(rowsAboutToBeInsertedSpyRead.count(), 3);
QCOMPARE(rowsAboutToBeInsertedSpyRead.count(), 1);
QCOMPARE(rowsRemovedSpyRead.count(), 0);
QCOMPARE(rowsMovedSpyRead.count(), 0);
QCOMPARE(rowsInsertedSpyRead.count(), 3);
QCOMPARE(persistentStateChangedSpyRead.count(), 4);
QCOMPARE(rowsInsertedSpyRead.count(), 1);
QCOMPARE(persistentStateChangedSpyRead.count(), 1);
QCOMPARE(dataChangedSpyRead.count(), 6);
QCOMPARE(newTrackByNameInListSpyRead.count(), 3);
QCOMPARE(newEntryInListSpyRead.count(), 0);
......@@ -5901,23 +5802,6 @@ void MediaPlayListTest::testRestoreSettings()
connect(&myDatabaseContent, &DatabaseInterface::tracksAdded,
&myListener, &TracksListener::tracksAdded);
QVariantMap settings;
settings[QStringLiteral("currentTrack")] = 2;
settings[QStringLiteral("randomPlay")] = true;
settings[QStringLiteral("repeatPlay")] = true;
myPlayList.setPersistentState(settings);
QCOMPARE(currentTrackChangedSpy.count(), 0);
QCOMPARE(randomPlayChangedSpy.count(), 1);
QCOMPARE(repeatPlayChangedSpy.count(), 1);
QCOMPARE(playListFinishedSpy.count(), 0);
QCOMPARE(currentTrackChangedSpy.count(), 0);
QCOMPARE(randomPlayChangedSpy.count(), 1);
QCOMPARE(repeatPlayChangedSpy.count(), 1);
QCOMPARE(playListFinishedSpy.count(), 0);
myDatabaseContent.insertTracksList(mNewTracks, mNewCovers);
myPlayList.enqueue({{{DataTypes::DatabaseIdRole, myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1)}},
......@@ -5936,6 +5820,18 @@ void MediaPlayListTest::testRestoreSettings()
QVERIFY(currentTrackChangedSpy.wait());
QCOMPARE(currentTrackChangedSpy.count(), 1);
QCOMPARE(randomPlayChangedSpy.count(), 0);
QCOMPARE(repeatPlayChangedSpy.count(), 0);
QCOMPARE(playListFinishedSpy.count(), 0);
QVariantMap settings;
settings[QStringLiteral("currentTrack")] = 2;
settings[QStringLiteral("randomPlay")] = true;
settings[QStringLiteral("repeatPlay")] = true;
myPlayList.setPersistentState(settings);
QCOMPARE(currentTrackChangedSpy.count(), 2);
QCOMPARE(randomPlayChangedSpy.count(), 1);
QCOMPARE(repeatPlayChangedSpy.count(), 1);
QCOMPARE(playListFinishedSpy.count(), 0);
......
......@@ -343,7 +343,7 @@ private Q_SLOTS:
QCOMPARE(trackHasBeenRemovedSpy.count(), 0);
QCOMPARE(tracksListAddedSpy.count(), 0);
myPlayList.enqueueRestoredEntry({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1});
myPlayList.enqueueRestoredEntries(QVariantList({QStringList({{}, QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), QStringLiteral("1"), QStringLiteral("1"), {}})}));
QCOMPARE(trackHasChangedSpy.count(), 0);
QCOMPARE(trackHasBeenRemovedSpy.count(), 0);
......
......@@ -360,11 +360,11 @@ void ElisaApplication::initializeModels()
Q_EMIT musicManagerChanged();
d->mMediaPlayList = std::make_unique<MediaPlayList>();
d->mMusicManager->subscribeForTracks(d->mMediaPlayList.get());
Q_EMIT mediaPlayListChanged();
d->mMusicManager->setElisaApplication(this);
d->mMediaPlayList->setMusicListenersManager(d->mMusicManager.get());
QObject::connect(this, &ElisaApplication::enqueue,
d->mMediaPlayList.get(), static_cast<void (MediaPlayList::*)(const ElisaUtils::EntryDataList&,
ElisaUtils::PlayListEntryType,
......
......@@ -19,7 +19,6 @@
#include "playListLogging.h"
#include "datatypes.h"
#include "musiclistenersmanager.h"
#include <QUrl>
#include <QPersistentModelIndex>
......@@ -41,16 +40,12 @@ public:
QList<DataTypes::TrackDataType> mTrackData;
MusicListenersManager* mMusicListenersManager = nullptr;
QPersistentModelIndex mPreviousTrack;
QPersistentModelIndex mCurrentTrack;
QPersistentModelIndex mNextTrack;
QVariantMap mPersistentState;
QMediaPlaylist mLoadPlaylist;
int mCurrentPlayListPosition = 0;
......@@ -368,55 +363,70 @@ void MediaPlayList::move(int from, int to, int n)
}
}
void MediaPlayList::enqueueRestoredEntry(const MediaPlayListEntry &newEntry)
void MediaPlayList::enqueueRestoredEntries(const QVariantList &newEntries)
{
enqueueCommon();
beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + newEntries.size() - 1);
for (auto &oneData : newEntries) {
auto trackData = oneData.toStringList();
if (trackData.size() != 7) {
continue;
}
beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size());
d->mData.push_back(newEntry);
d->mTrackData.push_back({});
endInsertRows();
auto restoredId = trackData[0].toULongLong();
auto restoredTitle = trackData[1];
auto restoredArtist = trackData[2];
auto restoredAlbum = trackData[3];
auto restoredTrackNumber = trackData[4];
auto restoredDiscNumber = trackData[5];
restorePlayListPosition();
if (!d->mCurrentTrack.isValid()) {
resetCurrentTrack();
}
auto mEntryType = static_cast<ElisaUtils::PlayListEntryType>(trackData[6].toInt());
auto newEntry = MediaPlayListEntry({restoredId, restoredTitle, restoredArtist, restoredAlbum, restoredTrackNumber, restoredDiscNumber, mEntryType});
Q_EMIT tracksCountChanged();
Q_EMIT remainingTracksChanged();
Q_EMIT persistentStateChanged();
d->mData.push_back(newEntry);
d->mTrackData.push_back({});
if (!newEntry.mIsValid) {
if (newEntry.mEntryType == ElisaUtils::Radio) {
Q_EMIT newEntryInList(newEntry.mId, {}, ElisaUtils::Radio);
} else if (newEntry.mTrackUrl.isValid()) {
auto entryURL = newEntry.mTrackUrl.toUrl();
if (entryURL.isLocalFile()) {
auto entryString = entryURL.toLocalFile();
QFileInfo newTrackFile(entryString);
if (newTrackFile.exists()) {
d->mData.last().mIsValid = true;
if (!d->mCurrentTrack.isValid()) {
resetCurrentTrack();
}
if (!newEntry.mIsValid) {
if (newEntry.mEntryType == ElisaUtils::Radio) {
Q_EMIT newEntryInList(newEntry.mId, {}, ElisaUtils::Radio);
} else if (newEntry.mTrackUrl.isValid()) {
auto entryURL = newEntry.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, ElisaUtils::FileName);
}
Q_EMIT newEntryInList(0, entryString, ElisaUtils::FileName);
} else {
Q_EMIT newTrackByNameInList(newEntry.mTitle,
newEntry.mArtist,
newEntry.mAlbum,
newEntry.mTrackNumber,
newEntry.mDiscNumber);
}
} else {
Q_EMIT newTrackByNameInList(newEntry.mTitle,
newEntry.mArtist,
newEntry.mAlbum,
newEntry.mTrackNumber,
newEntry.mDiscNumber);
Q_EMIT newEntryInList(newEntry.mId, {}, ElisaUtils::Track);
}
} else {
Q_EMIT newEntryInList(newEntry.mId, {}, ElisaUtils::Track);
}
if (!newEntry.mIsValid) {
Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::IsPlayingRole});
if (!newEntry.mIsValid) {
Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::IsPlayingRole});
if (!d->mCurrentTrack.isValid()) {
resetCurrentTrack();
if (!d->mCurrentTrack.isValid()) {
resetCurrentTrack();
}
}
}
endInsertRows();
Q_EMIT tracksCountChanged();
Q_EMIT remainingTracksChanged();
}
void MediaPlayList::enqueueArtist(const QString &artistName)
......@@ -432,7 +442,6 @@ void MediaPlayList::enqueueArtist(const QString &artistName)
d->mTrackData.push_back({});
endInsertRows();
restorePlayListPosition();
if (!d->mCurrentTrack.isValid()) {
resetCurrentTrack();
}
......@@ -490,7 +499,6 @@ void MediaPlayList::enqueueFilesList(const ElisaUtils::EntryDataList &newEntries
}
endInsertRows();
restorePlayListPosition();
if (!d->mCurrentTrack.isValid()) {
resetCurrentTrack();
}
......@@ -516,7 +524,6 @@ void MediaPlayList::enqueueTracksListById(const ElisaUtils::EntryDataList &newEn
}
endInsertRows();
restorePlayListPosition();
if (!d->mCurrentTrack.isValid()) {
resetCurrentTrack();
}
......@@ -638,8 +645,6 @@ void MediaPlayList::undoClearPlayList()
}
endInsertRows();
d->mMusicListenersManager = dOld->mMusicListenersManager;
d->mPersistentState = dOld->mPersistentState;
d->mCurrentPlayListPosition = dOld->mCurrentPlayListPosition;
d->mRandomPlay = dOld->mRandomPlay;
d->mRepeatPlay = dOld->mRepeatPlay;
......@@ -677,9 +682,7 @@ void MediaPlayList::copyD()
{
dOld->mData = d->mData;
dOld->mTrackData = d->mTrackData;
dOld->mMusicListenersManager = d->mMusicListenersManager;
dOld->mCurrentTrack = d->mCurrentTrack;
dOld->mPersistentState = d->mPersistentState;
dOld->mCurrentPlayListPosition = d->mCurrentPlayListPosition;
dOld->mRandomPlay = d->mRandomPlay;
dOld->mRepeatPlay = d->mRepeatPlay;
......@@ -834,11 +837,11 @@ bool MediaPlayList::savePlaylist(const QUrl &fileName)
QVariantMap MediaPlayList::persistentState() const
{
auto currentState = QVariantMap();
auto result = QList<QVariant>();
QVariantMap currentState;
QVariantList result;
for (int trackIndex = 0; trackIndex < d->mData.size(); ++trackIndex) {
auto oneData = QList<QString>();
QStringList oneData;
const auto &oneEntry = d->mData[trackIndex];
if (oneEntry.mIsValid) {
const auto &oneTrack = d->mTrackData[trackIndex];
......@@ -875,11 +878,6 @@ QVariantMap MediaPlayList::persistentState() const
return currentState;
}
MusicListenersManager *MediaPlayList::musicListenersManager() const
{
return d->mMusicListenersManager;
}
int MediaPlayList::tracksCount() const
{
return rowCount();
......@@ -917,37 +915,31 @@ bool MediaPlayList::repeatPlay() const
void MediaPlayList::setPersistentState(const QVariantMap &persistentStateValue)
{
if (d->mPersistentState == persistentStateValue) {
return;
}
qDebug() << "MediaPlayList::setPersistentState" << persistentStateValue;
d->mPersistentState = persistentStateValue;
qCDebug(orgKdeElisaPlayList()) << "MediaPlayList::setPersistentState" << persistentStateValue;
auto persistentState = d->mPersistentState[QStringLiteral("playList")].toList();
auto playListIt = persistentStateValue.find(QStringLiteral("playList"));
if (playListIt != persistentStateValue.end()) {
const auto playList = playListIt.value().toList();
enqueueRestoredEntries(playList);
}
for (auto &oneData : persistentState) {
auto trackData = oneData.toStringList();
if (trackData.size() != 7) {
continue;
auto playerCurrentTrack = persistentStateValue.find(QStringLiteral("currentTrack"));
if (playerCurrentTrack != persistentStateValue.end()) {
auto newIndex = index(playerCurrentTrack->toInt(), 0);
if (newIndex.isValid() && (newIndex != d->mCurrentTrack)) {
d->mCurrentTrack = newIndex;
notifyCurrentTrackChanged();
}
auto restoredId = trackData[0].toULongLong();
auto restoredTitle = trackData[1];
auto restoredArtist = trackData[2];
auto restoredAlbum = trackData[3];
auto restoredTrackNumber = trackData[4];
auto restoredDiscNumber = trackData[5];
auto mEntryType = static_cast<ElisaUtils::PlayListEntryType>(trackData[6].toInt());
enqueueRestoredEntry({restoredId, restoredTitle, restoredArtist, restoredAlbum, restoredTrackNumber, restoredDiscNumber, mEntryType});
}
restorePlayListPosition();
restoreRandomPlay();
restoreRepeatPlay();
auto randomPlayStoredValue = persistentStateValue.find(QStringLiteral("randomPlay"));
if (randomPlayStoredValue != persistentStateValue.end()) {
setRandomPlay(randomPlayStoredValue->toBool());
}
auto repeatPlayStoredValue = persistentStateValue.find(QStringLiteral("repeatPlay"));
if (repeatPlayStoredValue != persistentStateValue.end()) {
setRepeatPlay(repeatPlayStoredValue->toBool());
}
Q_EMIT persistentStateChanged();
}
......@@ -1009,7 +1001,6 @@ void MediaPlayList::tracksListAdded(qulonglong newDatabaseId,
}
endInsertRows();
restorePlayListPosition();
if (!d->mCurrentTrack.isValid()) {
resetCurrentTrack();
}
......@@ -1056,8 +1047,6 @@ void MediaPlayList::trackChanged(const TrackDataType &track)
Q_EMIT dataChanged(index(i, 0), index(i, 0), {});
restorePlayListPosition();
if (!d->mCurrentTrack.isValid()) {
resetCurrentTrack();
}
......@@ -1073,8 +1062,6 @@ void MediaPlayList::trackChanged(const TrackDataType &track)
Q_EMIT dataChanged(index(i, 0), index(i, 0), {});
restorePlayListPosition();
if (!d->mCurrentTrack.isValid()) {
resetCurrentTrack();
}
......@@ -1107,8 +1094,6 @@ void MediaPlayList::trackChanged(const TrackDataType &track)
Q_EMIT dataChanged(index(i, 0), index(i, 0), {});
restorePlayListPosition();
if (!d->mCurrentTrack.isValid()) {
resetCurrentTrack();
} else if (i == d->mCurrentTrack.row()) {
......@@ -1129,8 +1114,6 @@ void MediaPlayList::trackChanged(const TrackDataType &track)
Q_EMIT dataChanged(index(i, 0), index(i, 0), {});
restorePlayListPosition();
if (!d->mCurrentTrack.isValid()) {
resetCurrentTrack();
} else if (i == d->mCurrentTrack.row()) {
......@@ -1168,21 +1151,6 @@ void MediaPlayList::trackRemoved(qulonglong trackId)
}
}
void MediaPlayList::setMusicListenersManager(MusicListenersManager *musicListenersManager)
{
if (d->mMusicListenersManager == musicListenersManager) {
return;
}