Commit ce3df0bb authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

let playlist get the full track data when possible

should avoid having the playlist gets corrupted when adding many tracks
from different albums

CCBUG: 398093
parent f37e0eb4
This diff is collapsed.
......@@ -100,7 +100,7 @@ private Q_SLOTS:
QCOMPARE(trackHasBeenRemovedSpy.count(), 0);
QCOMPARE(tracksListAddedSpy.count(), 0);
myPlayList.replaceAndPlay({0, QStringLiteral("artist1"), {}}, ElisaUtils::Artist);
myPlayList.replaceAndPlay({{}, QStringLiteral("artist1"), {}}, ElisaUtils::Artist);
QCOMPARE(trackHasChangedSpy.count(), 0);
QCOMPARE(trackHasBeenRemovedSpy.count(), 0);
......@@ -227,7 +227,7 @@ private Q_SLOTS:
QCOMPARE(trackId != 0, true);
myPlayList.replaceAndPlay(ElisaUtils::EntryData{trackId, {}, {}}, ElisaUtils::Track);
myPlayList.replaceAndPlay(ElisaUtils::EntryData{{{DataTypes::DatabaseIdRole, trackId}}, {}, {}}, ElisaUtils::Track);
QCOMPARE(trackHasChangedSpy.count(), 1);
QCOMPARE(trackHasBeenRemovedSpy.count(), 0);
......@@ -289,7 +289,7 @@ private Q_SLOTS:
QCOMPARE(trackHasBeenRemovedSpy.count(), 0);
QCOMPARE(tracksListAddedSpy.count(), 0);
myPlayList.enqueue({myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1),
myPlayList.enqueue({{{DataTypes::DatabaseIdRole, myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1)}},
QStringLiteral("track1"), {}},
ElisaUtils::Track);
......@@ -422,7 +422,7 @@ private Q_SLOTS:
QCOMPARE(trackHasBeenRemovedSpy.count(), 0);
QCOMPARE(tracksListAddedSpy.count(), 0);
myPlayList.enqueue({myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1),
myPlayList.enqueue({{{DataTypes::DatabaseIdRole, myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1)}},
QStringLiteral("track1"), {}},
ElisaUtils::Track);
......
......@@ -76,6 +76,7 @@ public:
PlayFrequency,
ElementTypeRole,
LyricsRole,
FullDataRole,
};
Q_ENUM(ColumnsRoles)
......
......@@ -212,7 +212,7 @@ void ElisaApplication::activateRequested(const QStringList &arguments, const QSt
continue;
}
realArguments.push_back(ElisaUtils::EntryData{0, {}, QUrl(oneArgument)});
realArguments.push_back(ElisaUtils::EntryData{{}, {}, QUrl(oneArgument)});
}
Q_EMIT enqueue(checkFileListAndMakeAbsolute(realArguments, workingDirectory),
......@@ -309,10 +309,10 @@ ElisaUtils::EntryDataList ElisaApplication::checkFileListAndMakeAbsolute(const E
}
if (newFile.exists()) {
filesToOpen.push_back(ElisaUtils::EntryData{0, {}, QUrl::fromLocalFile(newFile.canonicalFilePath())});
filesToOpen.push_back(ElisaUtils::EntryData{{}, {}, QUrl::fromLocalFile(newFile.canonicalFilePath())});
}
} else {
filesToOpen.push_back(ElisaUtils::EntryData{0, {}, std::get<2>(oneFile)});
filesToOpen.push_back(ElisaUtils::EntryData{{}, {}, std::get<2>(oneFile)});
}
}
......
......@@ -20,6 +20,8 @@
#include "elisaLib_export.h"
#include "datatypes.h"
#include <QList>
#include <QUrl>
#include <QString>
......@@ -44,7 +46,7 @@ enum PlayListEnqueueTriggerPlay {
Q_ENUM_NS(PlayListEnqueueTriggerPlay)
using EntryData = std::tuple<qulonglong, QString, QUrl>;
using EntryData = std::tuple<DataTypes::TrackDataType, QString, QUrl>;
using EntryDataList = QList<EntryData>;
enum PlayListEntryType {
......
......@@ -112,7 +112,7 @@ QHash<int, QByteArray> MediaPlayList::roleNames() const
roles[static_cast<int>(ColumnsRoles::ImageUrlRole)] = "imageUrl";
roles[static_cast<int>(ColumnsRoles::ShadowForImageRole)] = "shadowForImage";
roles[static_cast<int>(ColumnsRoles::ResourceRole)] = "trackResource";
roles[static_cast<int>(ColumnsRoles::TrackDataRole)] = "trackData";
roles[static_cast<int>(ColumnsRoles::FullDataRole)] = "trackData";
roles[static_cast<int>(ColumnsRoles::AlbumIdRole)] = "albumId";
roles[static_cast<int>(ColumnsRoles::AlbumSectionRole)] = "albumSection";
roles[static_cast<int>(ColumnsRoles::ElementTypeRole)] = "entryType";
......@@ -509,9 +509,9 @@ void MediaPlayList::enqueueTracksListById(const ElisaUtils::EntryDataList &newEn
beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + newEntries.size() - 1);
for (const auto &newTrack : newEntries) {
auto newMediaPlayListEntry = MediaPlayListEntry{std::get<0>(newTrack), std::get<1>(newTrack), type};
auto newMediaPlayListEntry = MediaPlayListEntry{std::get<0>(newTrack).databaseId(), std::get<1>(newTrack), type};
d->mData.push_back(newMediaPlayListEntry);
d->mTrackData.push_back({});
d->mTrackData.push_back(std::get<0>(newTrack));
Q_EMIT newEntryInList(newMediaPlayListEntry.mId, newMediaPlayListEntry.mTitle.toString(), newMediaPlayListEntry.mEntryType);
}
endInsertRows();
......@@ -534,9 +534,9 @@ void MediaPlayList::enqueueOneEntry(const ElisaUtils::EntryData &entryData, Elis
enqueueCommon();
beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size());
d->mData.push_back(MediaPlayListEntry{std::get<0>(entryData), std::get<1>(entryData), type});
d->mTrackData.push_back({});
Q_EMIT newEntryInList(std::get<0>(entryData), std::get<1>(entryData), type);
d->mData.push_back(MediaPlayListEntry{std::get<0>(entryData).databaseId(), std::get<1>(entryData), type});
d->mTrackData.push_back(std::get<0>(entryData));
Q_EMIT newEntryInList(std::get<0>(entryData).databaseId(), std::get<1>(entryData), type);
endInsertRows();
Q_EMIT tracksCountChanged();
......@@ -553,14 +553,15 @@ void MediaPlayList::enqueueMultipleEntries(const ElisaUtils::EntryDataList &entr
for (const auto &entryData : entriesData) {
if (std::get<2>(entryData).isValid()) {
d->mData.push_back(MediaPlayListEntry{std::get<2>(entryData)});
d->mTrackData.push_back({});
} else {
d->mData.push_back(MediaPlayListEntry{std::get<0>(entryData), std::get<1>(entryData), type});
d->mData.push_back(MediaPlayListEntry{std::get<0>(entryData).databaseId(), std::get<1>(entryData), type});
d->mTrackData.push_back(std::get<0>(entryData));
}
d->mTrackData.push_back({});
if (std::get<2>(entryData).isValid()) {
Q_EMIT newUrlInList(std::get<2>(entryData), type);
} else {
Q_EMIT newEntryInList(std::get<0>(entryData), std::get<1>(entryData), type);
Q_EMIT newEntryInList(std::get<0>(entryData).databaseId(), std::get<1>(entryData), type);
}
}
endInsertRows();
......@@ -712,7 +713,7 @@ void MediaPlayList::enqueue(qulonglong newEntryDatabaseId,
ElisaUtils::PlayListEnqueueMode enqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay)
{
enqueue(ElisaUtils::EntryData{newEntryDatabaseId, newEntryTitle, {}}, databaseIdType, enqueueMode, triggerPlay);
enqueue(ElisaUtils::EntryData{{{DataTypes::DatabaseIdRole, newEntryDatabaseId}}, newEntryTitle, {}}, databaseIdType, enqueueMode, triggerPlay);
}
void MediaPlayList::enqueue(const QUrl &entryUrl, ElisaUtils::PlayListEntryType databaseIdType,
......@@ -968,6 +969,11 @@ void MediaPlayList::tracksListAdded(qulonglong newDatabaseId,
ElisaUtils::PlayListEntryType databaseIdType,
const ListTrackDataType &tracks)
{
if (tracks.isEmpty()) {
qDebug() << "empty tracks list";
return;
}
for (int playListIndex = 0; playListIndex < d->mData.size(); ++playListIndex) {
auto &oneEntry = d->mData[playListIndex];
if (oneEntry.mEntryType != databaseIdType) {
......
......@@ -127,8 +127,8 @@ public:
PlayFrequency,
ElementTypeRole,
LyricsRole,
FullDataRole,
IsValidRole,
TrackDataRole,
CountRole,
IsPlayingRole,
AlbumSectionRole,
......
......@@ -63,7 +63,7 @@ void AllTracksProxyModel::genericEnqueueToPlayList(ElisaUtils::PlayListEnqueueMo
allTracks.reserve(rowCount());
for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) {
auto currentIndex = index(rowIndex, 0);
allTracks.push_back(ElisaUtils::EntryData{data(currentIndex, DataTypes::ColumnsRoles::DatabaseIdRole).toULongLong(),
allTracks.push_back(ElisaUtils::EntryData{data(currentIndex, DataTypes::FullDataRole).value<DataTypes::TrackDataType>(),
data(currentIndex, DataTypes::ColumnsRoles::TitleRole).toString(), {}});
}
Q_EMIT entriesToEnqueue(allTracks, ElisaUtils::Track, enqueueMode, triggerPlay);
......
......@@ -107,6 +107,7 @@ QHash<int, QByteArray> DataModel::roleNames() const
roles[static_cast<int>(DataTypes::ColumnsRoles::DiscNumberRole)] = "discNumber";
roles[static_cast<int>(DataTypes::ColumnsRoles::RatingRole)] = "rating";
roles[static_cast<int>(DataTypes::ColumnsRoles::IsSingleDiscAlbumRole)] = "isSingleDiscAlbum";
roles[static_cast<int>(DataTypes::ColumnsRoles::FullDataRole)] = "fullData";
return roles;
}
......@@ -247,6 +248,31 @@ QVariant DataModel::data(const QModelIndex &index, int role) const
}
break;
}
case DataTypes::ColumnsRoles::FullDataRole:
switch (d->mModelType)
{
case ElisaUtils::Track:
result = QVariant::fromValue(d->mAllTrackData[index.row()]);
break;
case ElisaUtils::Radio:
result = QVariant::fromValue(d->mAllRadiosData[index.row()]);
break;
case ElisaUtils::Album:
result = QVariant::fromValue(d->mAllAlbumData[index.row()]);
break;
case ElisaUtils::Artist:
result = QVariant::fromValue(d->mAllArtistData[index.row()]);
break;
case ElisaUtils::Genre:
result = QVariant::fromValue(d->mAllGenreData[index.row()]);
break;
case ElisaUtils::Lyricist:
case ElisaUtils::Composer:
case ElisaUtils::FileName:
case ElisaUtils::Unknown:
break;
}
break;
default:
switch(d->mModelType)
{
......
......@@ -94,7 +94,7 @@ void FileBrowserProxyModel::enqueueToPlayList()
for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) {
auto currentIndex = index(rowIndex, 0);
if (!data(currentIndex, FileBrowserModel::IsDirectoryRole).toBool()) {
allTrackUrls.push_back({0, {}, data(currentIndex, FileBrowserModel::FileUrlRole).toUrl()});
allTrackUrls.push_back({{}, {}, data(currentIndex, FileBrowserModel::FileUrlRole).toUrl()});
}
}
Q_EMIT filesToEnqueue(allTrackUrls,
......@@ -112,7 +112,7 @@ void FileBrowserProxyModel::replaceAndPlayOfPlayList()
for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) {
auto currentIndex = index(rowIndex, 0);
if (!data(currentIndex, FileBrowserModel::IsDirectoryRole).toBool()) {
allTrackUrls.push_back({0, {}, data(currentIndex, FileBrowserModel::FileUrlRole).toUrl()});
allTrackUrls.push_back({{}, {}, data(currentIndex, FileBrowserModel::FileUrlRole).toUrl()});
}
}
Q_EMIT filesToEnqueue(allTrackUrls,
......
......@@ -84,7 +84,7 @@ void GridViewProxyModel::genericEnqueueToPlayList(ElisaUtils::PlayListEnqueueMod
allData.reserve(rowCount());
for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) {
auto currentIndex = index(rowIndex, 0);
allData.push_back(ElisaUtils::EntryData{data(currentIndex, DataTypes::DatabaseIdRole).toULongLong(),
allData.push_back(ElisaUtils::EntryData{data(currentIndex, DataTypes::FullDataRole).value<DataTypes::TrackDataType>(),
data(currentIndex, Qt::DisplayRole).toString(), {}});
}
Q_EMIT entriesToEnqueue(allData, mDataType, enqueueMode, triggerPlay);
......
......@@ -56,7 +56,7 @@ void SingleAlbumProxyModel::genericEnqueueToPlayList(ElisaUtils::PlayListEnqueue
allTracks.reserve(rowCount());
for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) {
auto currentIndex = index(rowIndex, 0);
allTracks.push_back(ElisaUtils::EntryData{data(currentIndex, DataTypes::ColumnsRoles::DatabaseIdRole).toULongLong(),
allTracks.push_back(ElisaUtils::EntryData{data(currentIndex, DataTypes::FullDataRole).value<DataTypes::TrackDataType>(),
data(currentIndex, DataTypes::ColumnsRoles::TitleRole).toString(), {}});
}
Q_EMIT entriesToEnqueue(allTracks, ElisaUtils::Track, enqueueMode, triggerPlay);
......
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