Commit 6e78d938 authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

Allow to restore entries in play list from local or remote URLs

one can have files in the playlist that are not in the database. In this
case restore at startup will fail.

also store the url and try to restore it correctly at start.

try to ensure a smooth transition
parent b7e2590f
Pipeline #42669 passed with stage
in 26 seconds
......@@ -313,7 +313,7 @@ void MediaPlayList::enqueueRestoredEntries(const QVariantList &newEntries)
beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + newEntries.size() - 1);
for (auto &oneData : newEntries) {
auto trackData = oneData.toStringList();
if (trackData.size() != 7) {
if (trackData.size() != 7 && trackData.size() != 8) {
continue;
}
......@@ -323,35 +323,37 @@ void MediaPlayList::enqueueRestoredEntries(const QVariantList &newEntries)
auto restoredAlbum = trackData[3];
auto restoredTrackNumber = trackData[4];
auto restoredDiscNumber = trackData[5];
auto restoredFileUrl = QVariant{};
if (trackData.size() == 8) {
restoredFileUrl = QUrl{trackData[7]};
}
auto mEntryType = static_cast<ElisaUtils::PlayListEntryType>(trackData[6].toInt());
auto newEntry = MediaPlayListEntry({restoredId, restoredTitle, restoredArtist, restoredAlbum, restoredTrackNumber, restoredDiscNumber, mEntryType});
auto newEntry = MediaPlayListEntry({restoredId, restoredTitle, restoredArtist, restoredAlbum, restoredFileUrl, restoredTrackNumber, restoredDiscNumber, mEntryType});
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;
}
Q_EMIT newEntryInList(0, entryString, ElisaUtils::FileName);
if (newEntry.mEntryType == ElisaUtils::Radio) {
Q_EMIT newEntryInList(newEntry.mId, {}, ElisaUtils::Radio);
} else if (newEntry.mTitle.toString().isEmpty() && 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);
} else {
Q_EMIT newTrackByNameInList(newEntry.mTitle,
newEntry.mArtist,
newEntry.mAlbum,
newEntry.mTrackNumber,
newEntry.mDiscNumber);
d->mData.last().mIsValid = true;
}
} else {
Q_EMIT newEntryInList(newEntry.mId, {}, ElisaUtils::Track);
Q_EMIT newTrackByNameInList(newEntry.mTitle,
newEntry.mArtist,
newEntry.mAlbum,
newEntry.mTrackNumber,
newEntry.mDiscNumber);
}
}
endInsertRows();
......@@ -501,6 +503,7 @@ QVariantList MediaPlayList::getEntriesForRestore() const
oneData.push_back({});
}
oneData.push_back(QString::number(oneEntry.mEntryType));
oneData.push_back(oneTrack.resourceURI().toString());
result.push_back(QVariant(oneData));
}
......
......@@ -168,10 +168,11 @@ public:
mTrackNumber(trackNumber), mDiscNumber(discNumber), mEntryType(entryType) {
}
MediaPlayListEntry(qulonglong id, QVariant title, QVariant artist, QVariant album,
MediaPlayListEntry(qulonglong id, QVariant title, QVariant artist,
QVariant album, QVariant trackUrl,
QVariant trackNumber, QVariant discNumber,
ElisaUtils::PlayListEntryType entryType = ElisaUtils::Unknown)
: mTitle(std::move(title)), mAlbum(std::move(album)), mArtist(std::move(artist)),
: mTitle(std::move(title)), mAlbum(std::move(album)), mArtist(std::move(artist)), mTrackUrl(std::move(trackUrl)),
mTrackNumber(std::move(trackNumber)), mDiscNumber(std::move(discNumber)), mId(id), mEntryType(entryType) {
}
......
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