Commit 6336cb6c authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

fix removal of year field (and a few more fields)

parent 54ec9904
......@@ -5443,6 +5443,73 @@ private Q_SLOTS:
qDebug() << trackIdFirstVersion << secondTrackDataVersion;
}
void removeYear()
{
QTemporaryFile databaseFile;
databaseFile.open();
qDebug() << "removeYear" << databaseFile.fileName();
DatabaseInterface musicDb;
QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded);
QSignalSpy musicDbErrorSpy(&musicDb, &DatabaseInterface::databaseError);
QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified);
musicDb.init(QStringLiteral("testDb"), databaseFile.fileName());
musicDb.insertTracksList(mNewTracks, mNewCovers);
musicDbTrackAddedSpy.wait(300);
QCOMPARE(musicDb.allAlbumsData().count(), 5);
QCOMPARE(musicDbErrorSpy.count(), 0);
QCOMPARE(musicDbTrackModifiedSpy.count(), 0);
auto newTracks = DataTypes::ListTrackDataType{
{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"),
QStringLiteral("artist2"), QStringLiteral("album3"), {},
6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/test/$23"))},
QDateTime::fromMSecsSinceEpoch(23),
QUrl::fromLocalFile(QStringLiteral("album3")), 5, true,
QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1"), false}};
auto newCovers = mNewCovers;
newCovers[QStringLiteral("/test/$23")] = QUrl::fromLocalFile(QStringLiteral("album3"));
newCovers[QStringLiteral("/test/$24")] = QUrl::fromLocalFile(QStringLiteral("album3"));
newCovers[QStringLiteral("/test/$25")] = QUrl::fromLocalFile(QStringLiteral("album3"));
musicDb.insertTracksList(newTracks, newCovers);
QCOMPARE(musicDb.allAlbumsData().count(), 6);
QCOMPARE(musicDbErrorSpy.count(), 0);
QCOMPARE(musicDbTrackModifiedSpy.count(), 0);
auto trackIdFirstVersion = musicDb.trackIdFromFileName(QUrl::fromLocalFile(QStringLiteral("/test/$23")));
auto firstTrackDataVersion = musicDb.trackDataFromDatabaseId(trackIdFirstVersion);
auto newTrackData = firstTrackDataVersion;
newTrackData.remove(DataTypes::YearRole);
musicDb.insertTracksList({newTrackData}, newCovers);
QCOMPARE(musicDb.allAlbumsData().count(), 6);
QCOMPARE(musicDbErrorSpy.count(), 0);
QCOMPARE(musicDbTrackModifiedSpy.count(), 1);
auto trackIdSecondVersion = musicDb.trackIdFromFileName(QUrl::fromLocalFile(QStringLiteral("/test/$23")));
QCOMPARE(trackIdFirstVersion, trackIdSecondVersion);
auto secondTrackDataVersion = musicDb.trackDataFromDatabaseId(trackIdSecondVersion);
auto modifiedTrack = musicDbTrackModifiedSpy.at(0).at(0).value<DataTypes::TrackDataType>();
auto trackIdIterator = secondTrackDataVersion.find(DataTypes::YearRole);
QCOMPARE(trackIdIterator, secondTrackDataVersion.end());
QCOMPARE(secondTrackDataVersion, modifiedTrack);
}
};
QTEST_GUILESS_MAIN(DatabaseInterfaceTests)
......
......@@ -6798,9 +6798,18 @@ qulonglong DatabaseInterface::internalInsertTrack(const DataTypes::TrackDataType
auto isSameTrack = true;
isSameTrack = isSameTrack && (oldTrack.title() == oneTrack.title());
isSameTrack = isSameTrack && (oldTrack.album() == oneTrack.album());
isSameTrack = isSameTrack && (oldTrack.artist() == oneTrack.artist());
isSameTrack = isSameTrack && (oldTrack.albumArtist() == oneTrack.albumArtist());
isSameTrack = isSameTrack && (oldTrack.hasAlbum() == oneTrack.hasAlbum());
if (isSameTrack && oldTrack.hasAlbum()) {
isSameTrack = isSameTrack && (oldTrack.album() == oneTrack.album());
}
isSameTrack = isSameTrack && (oldTrack.hasArtist() == oneTrack.hasArtist());
if (isSameTrack && oldTrack.hasArtist()) {
isSameTrack = isSameTrack && (oldTrack.artist() == oneTrack.artist());
}
isSameTrack = isSameTrack && (oldTrack.hasAlbumArtist() == oneTrack.hasAlbumArtist());
if (isSameTrack && oldTrack.hasAlbumArtist()) {
isSameTrack = isSameTrack && (oldTrack.albumArtist() == oneTrack.albumArtist());
}
isSameTrack = isSameTrack && (oldTrack.hasTrackNumber() == oneTrack.hasTrackNumber());
if (isSameTrack && oldTrack.hasTrackNumber()) {
isSameTrack = isSameTrack && (oldTrack.trackNumber() == oneTrack.trackNumber());
......@@ -6812,11 +6821,26 @@ qulonglong DatabaseInterface::internalInsertTrack(const DataTypes::TrackDataType
isSameTrack = isSameTrack && (oldTrack.duration() == oneTrack.duration());
isSameTrack = isSameTrack && (oldTrack.rating() == oneTrack.rating());
isSameTrack = isSameTrack && (oldTrack.resourceURI() == oneTrack.resourceURI());
isSameTrack = isSameTrack && (oldTrack.genre() == oneTrack.genre());
isSameTrack = isSameTrack && (oldTrack.composer() == oneTrack.composer());
isSameTrack = isSameTrack && (oldTrack.lyricist() == oneTrack.lyricist());
isSameTrack = isSameTrack && (oldTrack.comment() == oneTrack.comment());
isSameTrack = isSameTrack && (oldTrack.year() == oneTrack.year());
isSameTrack = isSameTrack && (oldTrack.hasGenre() == oneTrack.hasGenre());
if (isSameTrack && oldTrack.hasGenre()) {
isSameTrack = isSameTrack && (oldTrack.genre() == oneTrack.genre());
}
isSameTrack = isSameTrack && (oldTrack.hasComposer() == oneTrack.hasComposer());
if (isSameTrack && oldTrack.hasComposer()) {
isSameTrack = isSameTrack && (oldTrack.composer() == oneTrack.composer());
}
isSameTrack = isSameTrack && (oldTrack.hasLyricist() == oneTrack.hasLyricist());
if (isSameTrack && oldTrack.hasLyricist()) {
isSameTrack = isSameTrack && (oldTrack.lyricist() == oneTrack.lyricist());
}
isSameTrack = isSameTrack && (oldTrack.hasComment() == oneTrack.hasComment());
if (isSameTrack && oldTrack.hasComment()) {
isSameTrack = isSameTrack && (oldTrack.comment() == oneTrack.comment());
}
isSameTrack = isSameTrack && (oldTrack.hasYear() == oneTrack.hasYear());
if (isSameTrack && oldTrack.hasYear()) {
isSameTrack = isSameTrack && (oldTrack.year() == oneTrack.year());
}
isSameTrack = isSameTrack && (oldTrack.hasChannels() == oneTrack.hasChannels());
if (isSameTrack && oldTrack.hasChannels()) {
isSameTrack = isSameTrack && (oldTrack.channels() == oneTrack.channels());
......@@ -7414,9 +7438,17 @@ void DatabaseInterface::updateTrackInDatabase(const DataTypes::TrackDataType &on
d->mUpdateTrackQuery.bindValue(QStringLiteral(":fileName"), oneTrack.resourceURI());
d->mUpdateTrackQuery.bindValue(QStringLiteral(":trackId"), oneTrack.databaseId());
d->mUpdateTrackQuery.bindValue(QStringLiteral(":title"), oneTrack.title());
insertArtist(oneTrack.artist());
d->mUpdateTrackQuery.bindValue(QStringLiteral(":artistName"), oneTrack.artist());
d->mUpdateTrackQuery.bindValue(QStringLiteral(":albumTitle"), oneTrack.album());
if (oneTrack.hasArtist()) {
insertArtist(oneTrack.artist());
d->mUpdateTrackQuery.bindValue(QStringLiteral(":artistName"), oneTrack.artist());
} else {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":artistName"), {});
}
if (oneTrack.hasAlbum()) {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":albumTitle"), oneTrack.album());
} else {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":albumTitle"), {});
}
if (oneTrack.hasAlbumArtist()) {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":albumArtistName"), oneTrack.albumArtist());
} else {
......@@ -7435,23 +7467,43 @@ void DatabaseInterface::updateTrackInDatabase(const DataTypes::TrackDataType &on
}
d->mUpdateTrackQuery.bindValue(QStringLiteral(":trackDuration"), QVariant::fromValue<qlonglong>(oneTrack.duration().msecsSinceStartOfDay()));
d->mUpdateTrackQuery.bindValue(QStringLiteral(":trackRating"), oneTrack.rating());
if (insertGenre(oneTrack.genre()) != 0) {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":genre"), oneTrack.genre());
if (oneTrack.hasGenre()) {
if (insertGenre(oneTrack.genre()) != 0) {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":genre"), oneTrack.genre());
} else {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":genre"), {});
}
} else {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":genre"), {});
}
if (insertComposer(oneTrack.composer()) != 0) {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":composer"), oneTrack.composer());
if (oneTrack.hasComposer()) {
if (insertComposer(oneTrack.composer()) != 0) {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":composer"), oneTrack.composer());
} else {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":composer"), {});
}
} else {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":composer"), {});
}
if (insertLyricist(oneTrack.lyricist()) != 0) {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":lyricist"), oneTrack.lyricist());
if (oneTrack.hasLyricist()) {
if (insertLyricist(oneTrack.lyricist()) != 0) {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":lyricist"), oneTrack.lyricist());
} else {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":lyricist"), {});
}
} else {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":lyricist"), {});
}
d->mUpdateTrackQuery.bindValue(QStringLiteral(":comment"), oneTrack.comment());
d->mUpdateTrackQuery.bindValue(QStringLiteral(":year"), oneTrack.year());
if (oneTrack.hasYear()) {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":comment"), oneTrack.comment());
} else {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":comment"), {});
}
if (oneTrack.hasYear()) {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":year"), oneTrack.year());
} else {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":year"), {});
}
if (oneTrack.hasChannels()) {
d->mUpdateTrackQuery.bindValue(QStringLiteral(":channels"), oneTrack.channels());
} else {
......
......@@ -144,6 +144,11 @@ public:
return operator[](key_type::ArtistRole).toString();
}
[[nodiscard]] bool hasArtist() const
{
return find(key_type::ArtistRole) != end();
}
[[nodiscard]] qulonglong albumId() const
{
return operator[](key_type::AlbumIdRole).toULongLong();
......@@ -219,31 +224,61 @@ public:
return operator[](key_type::GenreRole).toString();
}
[[nodiscard]] bool hasGenre() const
{
return find(key_type::GenreRole) != end();
}
[[nodiscard]] QString composer() const
{
return operator[](key_type::ComposerRole).toString();
}
[[nodiscard]] bool hasComposer() const
{
return find(key_type::ComposerRole) != end();
}
[[nodiscard]] QString lyricist() const
{
return operator[](key_type::LyricistRole).toString();
}
[[nodiscard]] bool hasLyricist() const
{
return find(key_type::LyricistRole) != end();
}
[[nodiscard]] QString lyrics() const
{
return operator[](key_type::LyricsRole).toString();
}
[[nodiscard]] bool hasLyrics() const
{
return find(key_type::LyricsRole) != end();
}
[[nodiscard]] QString comment() const
{
return operator[](key_type::CommentRole).toString();
}
[[nodiscard]] bool hasComment() const
{
return find(key_type::CommentRole) != end();
}
[[nodiscard]] int year() const
{
return operator[](key_type::YearRole).toInt();
}
[[nodiscard]] bool hasYear() const
{
return find(key_type::YearRole) != end();
}
[[nodiscard]] int channels() const
{
return operator[](key_type::ChannelsRole).toInt();
......
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