Commit 61f06336 authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

fix the compilation album insertion

Summary:
partial fix for handling albums without album artist

partially handle the case of compilations not getting Various Artists as
album artist

BUG: 409147

Test Plan: all tests are fine and most common cases should be covered.

Reviewers: #elisa, ngraham, astippich

Reviewed By: #elisa, ngraham

Differential Revision: https://phabricator.kde.org/D22499
parent c6e8f3e5
This diff is collapsed.
......@@ -88,7 +88,7 @@ private Q_SLOTS:
QCOMPARE(dataChangedSpy.count(), 0);
albumsModel.initialize(nullptr, nullptr, ElisaUtils::Track, ElisaUtils::FilterById, {}, {},
musicDb.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists")));
musicDb.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"), QStringLiteral("/")));
QCOMPARE(beginInsertRowsSpy.count(), 0);
QCOMPARE(endInsertRowsSpy.count(), 0);
......@@ -96,7 +96,7 @@ private Q_SLOTS:
QCOMPARE(endRemoveRowsSpy.count(), 0);
QCOMPARE(dataChangedSpy.count(), 0);
albumsModel.tracksAdded(musicDb.albumData(musicDb.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"))));
albumsModel.tracksAdded(musicDb.albumData(musicDb.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"), QStringLiteral("/"))));
QCOMPARE(albumsModel.rowCount(), 4);
QCOMPARE(beginInsertRowsSpy.count(), 1);
......@@ -155,7 +155,7 @@ private Q_SLOTS:
QCOMPARE(dataChangedSpy.count(), 0);
albumsModel.initialize(nullptr, nullptr, ElisaUtils::Track, ElisaUtils::FilterById, {}, {},
musicDb.albumIdFromTitleAndArtist(QStringLiteral("album3"), QStringLiteral("artist2")));
musicDb.albumIdFromTitleAndArtist(QStringLiteral("album3"), QStringLiteral("artist2"), QStringLiteral("/")));
QCOMPARE(beginInsertRowsSpy.count(), 0);
QCOMPARE(endInsertRowsSpy.count(), 0);
......@@ -163,7 +163,7 @@ private Q_SLOTS:
QCOMPARE(endRemoveRowsSpy.count(), 0);
QCOMPARE(dataChangedSpy.count(), 0);
albumsModel.tracksAdded(musicDb.albumData(musicDb.albumIdFromTitleAndArtist(QStringLiteral("album3"), QStringLiteral("artist2"))));
albumsModel.tracksAdded(musicDb.albumData(musicDb.albumIdFromTitleAndArtist(QStringLiteral("album3"), QStringLiteral("artist2"), QStringLiteral("/"))));
QCOMPARE(albumsModel.rowCount(), 3);
QCOMPARE(beginInsertRowsSpy.count(), 1);
......@@ -236,7 +236,7 @@ private Q_SLOTS:
QCOMPARE(dataChangedSpy.count(), 0);
albumsModel.initialize(nullptr, nullptr, ElisaUtils::Track, ElisaUtils::FilterById, {}, {},
musicDb.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists")));
musicDb.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"), QStringLiteral("/")));
QCOMPARE(beginInsertRowsSpy.count(), 0);
QCOMPARE(endInsertRowsSpy.count(), 0);
......@@ -244,7 +244,7 @@ private Q_SLOTS:
QCOMPARE(endRemoveRowsSpy.count(), 0);
QCOMPARE(dataChangedSpy.count(), 0);
albumsModel.tracksAdded(musicDb.albumData(musicDb.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"))));
albumsModel.tracksAdded(musicDb.albumData(musicDb.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"), QStringLiteral("/"))));
QCOMPARE(albumsModel.rowCount(), 4);
QCOMPARE(beginInsertRowsSpy.count(), 1);
......@@ -352,7 +352,7 @@ private Q_SLOTS:
QCOMPARE(dataChangedSpy.count(), 0);
albumsModel.initialize(nullptr, nullptr, ElisaUtils::Track, ElisaUtils::FilterById, {}, {},
musicDb.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists")));
musicDb.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"), QStringLiteral("/")));
QCOMPARE(beginInsertRowsSpy.count(), 0);
QCOMPARE(endInsertRowsSpy.count(), 0);
......@@ -360,7 +360,7 @@ private Q_SLOTS:
QCOMPARE(endRemoveRowsSpy.count(), 0);
QCOMPARE(dataChangedSpy.count(), 0);
albumsModel.tracksAdded(musicDb.albumData(musicDb.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"))));
albumsModel.tracksAdded(musicDb.albumData(musicDb.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"), QStringLiteral("/"))));
QCOMPARE(albumsModel.rowCount(), 4);
QCOMPARE(beginInsertRowsSpy.count(), 1);
......@@ -1444,7 +1444,8 @@ private Q_SLOTS:
QCOMPARE(dataChangedSpy.count(), 0);
auto albumId = musicDb.albumIdFromTitleAndArtist(QStringLiteral("album1"),
QStringLiteral("Various Artists"));
QStringLiteral("Various Artists"),
QStringLiteral("/"));
QVERIFY(albumId != 0);
......@@ -1534,7 +1535,7 @@ private Q_SLOTS:
QCOMPARE(dataChangedSpy.count(), 0);
albumsModel.initialize(nullptr, nullptr, ElisaUtils::Track, ElisaUtils::FilterById, {}, {},
musicDb.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists")));
musicDb.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"), QStringLiteral("/")));
QCOMPARE(beginInsertRowsSpy.count(), 0);
QCOMPARE(endInsertRowsSpy.count(), 0);
......@@ -1542,7 +1543,7 @@ private Q_SLOTS:
QCOMPARE(endRemoveRowsSpy.count(), 0);
QCOMPARE(dataChangedSpy.count(), 0);
albumsModel.tracksAdded(musicDb.albumData(musicDb.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"))));
albumsModel.tracksAdded(musicDb.albumData(musicDb.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"), QStringLiteral("/"))));
QCOMPARE(albumsModel.rowCount(), 4);
QCOMPARE(beginInsertRowsSpy.count(), 1);
......
......@@ -188,7 +188,7 @@ void MediaPlayListTest::enqueueAlbumCase()
QCOMPARE(newTrackByNameInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.count(), 0);
myPlayList.enqueue({myDatabaseContent.albumIdFromTitleAndArtist(QStringLiteral("album2"), QStringLiteral("artist1")),
myPlayList.enqueue({myDatabaseContent.albumIdFromTitleAndArtist(QStringLiteral("album2"), QStringLiteral("artist1"), QStringLiteral("/")),
QStringLiteral("album2")},
ElisaUtils::Album);
......@@ -316,7 +316,7 @@ void MediaPlayListTest::clearPlayListCase()
QCOMPARE(newEntryInListSpy.count(), 0);
QCOMPARE(currentTrackChangedSpy.count(), 0);
myPlayList.enqueue({myDatabaseContent.albumIdFromTitleAndArtist(QStringLiteral("album2"), QStringLiteral("artist1")),
myPlayList.enqueue({myDatabaseContent.albumIdFromTitleAndArtist(QStringLiteral("album2"), QStringLiteral("artist1"), QStringLiteral("/")),
QStringLiteral("album2")},
ElisaUtils::Album);
......@@ -462,7 +462,7 @@ void MediaPlayListTest::undoClearPlayListCase()
QCOMPARE(newEntryInListSpy.count(), 0);
QCOMPARE(currentTrackChangedSpy.count(), 0);
myPlayList.enqueue({myDatabaseContent.albumIdFromTitleAndArtist(QStringLiteral("album2"), QStringLiteral("artist1")),
myPlayList.enqueue({myDatabaseContent.albumIdFromTitleAndArtist(QStringLiteral("album2"), QStringLiteral("artist1"), QStringLiteral("/")),
QStringLiteral("album2")},
ElisaUtils::Album);
......@@ -667,7 +667,7 @@ void MediaPlayListTest::undoReplacePlayListCase()
QCOMPARE(newEntryInListSpy.count(), 0);
QCOMPARE(currentTrackChangedSpy.count(), 0);
myPlayList.enqueue({myDatabaseContent.albumIdFromTitleAndArtist(QStringLiteral("album2"), QStringLiteral("artist1")),
myPlayList.enqueue({myDatabaseContent.albumIdFromTitleAndArtist(QStringLiteral("album2"), QStringLiteral("artist1"), QStringLiteral("/")),
QStringLiteral("album2")},
ElisaUtils::Album);
......@@ -727,7 +727,7 @@ void MediaPlayListTest::undoReplacePlayListCase()
QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0)));
myPlayList.enqueue({myDatabaseContent.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists")),
myPlayList.enqueue({myDatabaseContent.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"), QStringLiteral("/")),
QStringLiteral("album1")},
ElisaUtils::Album,
ElisaUtils::ReplacePlayList,
......@@ -1023,7 +1023,7 @@ void MediaPlayListTest::removeFirstTrackOfAlbum()
QCOMPARE(newTrackByNameInListSpy.count(), 0);
QCOMPARE(newEntryInListSpy.count(), 0);
myPlayList.enqueue({myDatabaseContent.albumIdFromTitleAndArtist(QStringLiteral("album2"), QStringLiteral("artist1")),
myPlayList.enqueue({myDatabaseContent.albumIdFromTitleAndArtist(QStringLiteral("album2"), QStringLiteral("artist1"), QStringLiteral("/")),
QStringLiteral("album2")},
ElisaUtils::Album);
......@@ -2632,7 +2632,7 @@ void MediaPlayListTest::enqueueReplaceAndPlay()
QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TrackNumberRole).toInt(), 1);
QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::DiscNumberRole).toInt(), 1);
myPlayList.enqueue({myDatabaseContent.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists")),
myPlayList.enqueue({myDatabaseContent.albumIdFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"), QStringLiteral("/")),
QStringLiteral("album1")},
ElisaUtils::Album,
ElisaUtils::ReplacePlayList,
......
This diff is collapsed.
......@@ -60,6 +60,7 @@ public:
HighestTrackRating,
AlbumRole,
AlbumArtistRole,
IsValidAlbumArtistRole,
TrackNumberRole,
DiscNumberRole,
RatingRole,
......@@ -352,7 +353,7 @@ public:
Q_INVOKABLE void init(const QString &dbName, const QString &databaseFileName = {});
qulonglong albumIdFromTitleAndArtist(const QString &title, const QString &artist);
qulonglong albumIdFromTitleAndArtist(const QString &title, const QString &artist, const QString &albumPath);
ListTrackDataType allTracksData();
......@@ -458,7 +459,7 @@ private:
QList<qulonglong> fetchTrackIds(qulonglong albumId);
qulonglong internalAlbumIdFromTitleAndArtist(const QString &title, const QString &artist);
qulonglong internalAlbumIdFromTitleAndArtist(const QString &title, const QString &artist, const QString &albumPath);
MusicAudioTrack internalTrackFromDatabaseId(qulonglong id);
......@@ -479,7 +480,7 @@ private:
void initRequest();
qulonglong insertAlbum(const QString &title, const QString &albumArtist, const QString &trackArtist,
qulonglong insertAlbum(const QString &title, const QString &albumArtist,
const QString &trackPath, const QUrl &albumArtURI);
bool updateAlbumFromId(qulonglong albumId, const QUrl &albumArtUri,
......
......@@ -88,6 +88,7 @@ public:
HighestTrackRating,
AlbumRole,
AlbumArtistRole,
IsValidAlbumArtistRole,
TrackNumberRole,
DiscNumberRole,
RatingRole,
......
......@@ -168,6 +168,7 @@ QVariant TrackMetadataModel::data(const QModelIndex &index, int role) const
case DatabaseInterface::ChildModelRole:
case DatabaseInterface::StringDurationRole:
case DatabaseInterface::MilliSecondsDurationRole:
case DatabaseInterface::IsValidAlbumArtistRole:
case DatabaseInterface::AllArtistsRole:
case DatabaseInterface::HighestTrackRating:
case DatabaseInterface::ResourceRole:
......@@ -243,6 +244,7 @@ QVariant TrackMetadataModel::data(const QModelIndex &index, int role) const
case DatabaseInterface::ChildModelRole:
case DatabaseInterface::StringDurationRole:
case DatabaseInterface::MilliSecondsDurationRole:
case DatabaseInterface::IsValidAlbumArtistRole:
case DatabaseInterface::AllArtistsRole:
case DatabaseInterface::HighestTrackRating:
case DatabaseInterface::ResourceRole:
......
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