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

Merge branch 'release/19.12'

parents eb209bf8 df7bc03a
......@@ -4404,10 +4404,10 @@ private Q_SLOTS:
QCOMPARE(musicDb.allAlbumsData().count(), 5);
QCOMPARE(musicDb.allArtistsData().count(), 7);
QCOMPARE(musicDb.allTracksData().count(), 22);
QCOMPARE(musicDb.allTracksData().count(), 23);
QCOMPARE(musicDbArtistAddedSpy.count(), 1);
QCOMPARE(musicDbAlbumAddedSpy.count(), 1);
QCOMPARE(musicDbTrackAddedSpy.count(), 1);
QCOMPARE(musicDbTrackAddedSpy.count(), 2);
QCOMPARE(musicDbArtistRemovedSpy.count(), 0);
QCOMPARE(musicDbAlbumRemovedSpy.count(), 0);
QCOMPARE(musicDbTrackRemovedSpy.count(), 0);
......@@ -5247,6 +5247,76 @@ private Q_SLOTS:
QCOMPARE(albumFromGenreAndArtist.size(), 1);
}
void testTracksWithoutMetadata()
{
QTemporaryFile databaseFile;
databaseFile.open();
qDebug() << "testTracksWithoutMetadata" << databaseFile.fileName();
DatabaseInterface musicDb;
musicDb.init(QStringLiteral("testDb"), databaseFile.fileName());
QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded);
QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded);
QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded);
QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved);
QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved);
QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved);
QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified);
QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified);
QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError);
QCOMPARE(musicDb.allAlbumsData().count(), 0);
QCOMPARE(musicDb.allArtistsData().count(), 0);
QCOMPARE(musicDb.allTracksData().count(), 0);
QCOMPARE(musicDbArtistAddedSpy.count(), 0);
QCOMPARE(musicDbAlbumAddedSpy.count(), 0);
QCOMPARE(musicDbTrackAddedSpy.count(), 0);
QCOMPARE(musicDbArtistRemovedSpy.count(), 0);
QCOMPARE(musicDbAlbumRemovedSpy.count(), 0);
QCOMPARE(musicDbTrackRemovedSpy.count(), 0);
QCOMPARE(musicDbAlbumModifiedSpy.count(), 0);
QCOMPARE(musicDbTrackModifiedSpy.count(), 0);
QCOMPARE(musicDbDatabaseErrorSpy.count(), 0);
auto newTracks = DataTypes::ListTrackDataType {
{true, {}, {}, {}, {}, {}, {}, 0, 0, {}, {QUrl::fromLocalFile(QStringLiteral("/test/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {}, 0, true, {}, {}, {}, false},
{true, {}, {}, {}, {}, {}, {}, 0, 0, {}, {QUrl::fromLocalFile(QStringLiteral("/test/$24"))}, QDateTime::fromMSecsSinceEpoch(24), {}, 0, true, {}, {}, {}, false},
{true, {}, {}, {}, {}, {}, {}, 0, 0, {}, {QUrl::fromLocalFile(QStringLiteral("/test/$25"))}, QDateTime::fromMSecsSinceEpoch(25), {}, 0, true, {}, {}, {}, false}};
auto newCovers = mNewCovers;
musicDb.insertTracksList(newTracks, newCovers);
musicDbTrackAddedSpy.wait(300);
QCOMPARE(musicDb.allAlbumsData().count(), 0);
QCOMPARE(musicDb.allArtistsData().count(), 0);
QCOMPARE(musicDb.allTracksData().count(), 3);
QCOMPARE(musicDbArtistAddedSpy.count(), 0);
QCOMPARE(musicDbAlbumAddedSpy.count(), 0);
QCOMPARE(musicDbTrackAddedSpy.count(), 1);
QCOMPARE(musicDbArtistRemovedSpy.count(), 0);
QCOMPARE(musicDbAlbumRemovedSpy.count(), 0);
QCOMPARE(musicDbTrackRemovedSpy.count(), 0);
QCOMPARE(musicDbAlbumModifiedSpy.count(), 0);
QCOMPARE(musicDbTrackModifiedSpy.count(), 0);
QCOMPARE(musicDbDatabaseErrorSpy.count(), 0);
auto allTracks = musicDb.allTracksData();
QVERIFY(allTracks[0].title().isEmpty());
QCOMPARE(allTracks[0].resourceURI(), QUrl::fromLocalFile(QStringLiteral("/test/$23")));
QCOMPARE(allTracks[0].fileModificationTime(), QDateTime::fromMSecsSinceEpoch(23));
QVERIFY(allTracks[1].title().isEmpty());
QCOMPARE(allTracks[1].resourceURI(), QUrl::fromLocalFile(QStringLiteral("/test/$24")));
QCOMPARE(allTracks[1].fileModificationTime(), QDateTime::fromMSecsSinceEpoch(24));
QVERIFY(allTracks[2].title().isEmpty());
QCOMPARE(allTracks[2].resourceURI(), QUrl::fromLocalFile(QStringLiteral("/test/$25")));
QCOMPARE(allTracks[2].fileModificationTime(), QDateTime::fromMSecsSinceEpoch(25));
}
};
QTEST_GUILESS_MAIN(DatabaseInterfaceTests)
......
This diff is collapsed.
......@@ -96,7 +96,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);
......@@ -223,7 +223,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);
......@@ -285,7 +285,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);
......@@ -418,7 +418,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);
......
......@@ -84,7 +84,8 @@ public:
mQueryMaximumGenreIdQuery(mTracksDatabase), mSelectAllArtistsWithGenreFilterQuery(mTracksDatabase),
mSelectAllAlbumsShortWithGenreArtistFilterQuery(mTracksDatabase), mSelectAllAlbumsShortWithArtistFilterQuery(mTracksDatabase),
mSelectAllRecentlyPlayedTracksQuery(mTracksDatabase), mSelectAllFrequentlyPlayedTracksQuery(mTracksDatabase),
mClearTracksTable(mTracksDatabase), mClearAlbumsTable(mTracksDatabase), mClearArtistsTable(mTracksDatabase),
mClearTracksDataTable(mTracksDatabase), mClearTracksTable(mTracksDatabase),
mClearAlbumsTable(mTracksDatabase), mClearArtistsTable(mTracksDatabase),
mClearComposerTable(mTracksDatabase), mClearGenreTable(mTracksDatabase), mClearLyricistTable(mTracksDatabase),
mArtistMatchGenreQuery(mTracksDatabase), mSelectTrackIdQuery(mTracksDatabase),
mInsertRadioQuery(mTracksDatabase), mDeleteRadioQuery(mTracksDatabase),
......@@ -245,6 +246,8 @@ public:
QSqlQuery mSelectAllFrequentlyPlayedTracksQuery;
QSqlQuery mClearTracksDataTable;
QSqlQuery mClearTracksTable;
QSqlQuery mClearAlbumsTable;
......@@ -924,6 +927,18 @@ void DatabaseInterface::clearData()
d->mClearTracksTable.finish();
queryResult = execQuery(d->mClearTracksDataTable);
if (!queryResult || !d->mClearTracksDataTable.isActive()) {
Q_EMIT databaseError();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::clearData" << d->mClearTracksDataTable.lastQuery();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::clearData" << d->mClearTracksDataTable.boundValues();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::clearData" << d->mClearTracksDataTable.lastError();
}
d->mClearTracksDataTable.finish();
queryResult = execQuery(d->mClearAlbumsTable);
if (!queryResult || !d->mClearAlbumsTable.isActive()) {
......@@ -3913,9 +3928,12 @@ void DatabaseInterface::initRequest()
"tracksCover.`AlbumPath` = album.`AlbumPath` "
") as EmbeddedCover "
"FROM "
"`Tracks` tracks, "
"`TracksData` tracksMapping "
"LEFT JOIN "
"`Tracks` tracks "
"ON "
"tracksMapping.`FileName` = tracks.`FileName` "
"LEFT JOIN "
"`Albums` album "
"ON "
"tracks.`AlbumTitle` = album.`Title` AND "
......@@ -3925,7 +3943,7 @@ void DatabaseInterface::initRequest()
"LEFT JOIN `Composer` trackComposer ON trackComposer.`Name` = tracks.`Composer` "
"LEFT JOIN `Lyricist` trackLyricist ON trackLyricist.`Name` = tracks.`Lyricist` "
"WHERE "
"tracksMapping.`FileName` = tracks.`FileName` AND "
"tracks.`Title` IS NULL OR "
"tracks.`Priority` = ("
" SELECT "
" MIN(`Priority`) "
......@@ -4289,6 +4307,19 @@ void DatabaseInterface::initRequest()
}
}
{
auto clearTracksDataTableText = QStringLiteral("DELETE FROM `TracksData`");
auto result = prepareQuery(d->mClearTracksDataTable, clearTracksDataTableText);
if (!result) {
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::initRequest" << d->mClearTracksDataTable.lastQuery();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::initRequest" << d->mClearTracksDataTable.lastError();
Q_EMIT databaseError();
}
}
{
auto clearTracksTableText = QStringLiteral("DELETE FROM `Tracks`");
......@@ -5378,10 +5409,7 @@ void DatabaseInterface::initRequest()
"tracksMapping.`FileName`, "
"tracksMapping.`FileModifiedTime` "
"FROM "
"`TracksData` tracksMapping, "
"`Tracks` tracks "
"WHERE "
"tracks.`FileName` = tracksMapping.`FileName`");
"`TracksData` tracksMapping");
auto result = prepareQuery(d->mSelectAllTrackFilesQuery, selectAllTrackFilesFromSourceQueryText);
......@@ -6483,7 +6511,6 @@ qulonglong DatabaseInterface::internalInsertTrack(const DataTypes::TrackDataType
if (oneTrack.title().isEmpty()) {
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::internalInsertTrack" << oneTrack << "is not inserted";
return resultId;
}
QUrl::FormattingOptions currentOptions = QUrl::PreferLocalFile |
......@@ -6506,7 +6533,7 @@ qulonglong DatabaseInterface::internalInsertTrack(const DataTypes::TrackDataType
auto existingTrackId = internalTrackIdFromFileName(oneTrack.resourceURI());
bool isModifiedTrack = (existingTrackId != 0);
if (isModifiedTrack) {
if (isModifiedTrack && !oneTrack.title().isEmpty()) {
resultId = existingTrackId;
auto oldTrack = internalTrackFromDatabaseId(existingTrackId);
......@@ -6596,107 +6623,115 @@ qulonglong DatabaseInterface::internalInsertTrack(const DataTypes::TrackDataType
resultId = existingTrackId;
d->mInsertTrackQuery.bindValue(QStringLiteral(":trackId"), existingTrackId);
d->mInsertTrackQuery.bindValue(QStringLiteral(":fileName"), oneTrack.resourceURI());
d->mInsertTrackQuery.bindValue(QStringLiteral(":priority"), priority);
d->mInsertTrackQuery.bindValue(QStringLiteral(":title"), oneTrack.title());
insertArtist(oneTrack.artist());
d->mInsertTrackQuery.bindValue(QStringLiteral(":artistName"), oneTrack.artist());
d->mInsertTrackQuery.bindValue(QStringLiteral(":albumTitle"), oneTrack.album());
if (oneTrack.hasAlbumArtist()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":albumArtistName"), oneTrack.albumArtist());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":albumArtistName"), {});
}
d->mInsertTrackQuery.bindValue(QStringLiteral(":albumPath"), trackPath);
if (oneTrack.hasTrackNumber()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":trackNumber"), oneTrack.trackNumber());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":trackNumber"), {});
}
if (oneTrack.hasDiscNumber()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":discNumber"), oneTrack.discNumber());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":discNumber"), {});
}
d->mInsertTrackQuery.bindValue(QStringLiteral(":trackDuration"), QVariant::fromValue<qlonglong>(oneTrack.duration().msecsSinceStartOfDay()));
d->mInsertTrackQuery.bindValue(QStringLiteral(":trackRating"), oneTrack.rating());
if (insertGenre(oneTrack.genre()) != 0) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":genre"), oneTrack.genre());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":genre"), {});
}
if (insertComposer(oneTrack.composer()) != 0) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":composer"), oneTrack.composer());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":composer"), {});
}
if (insertLyricist(oneTrack.lyricist()) != 0) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":lyricist"), oneTrack.lyricist());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":lyricist"), {});
}
d->mInsertTrackQuery.bindValue(QStringLiteral(":comment"), oneTrack.comment());
d->mInsertTrackQuery.bindValue(QStringLiteral(":year"), oneTrack.year());
if (oneTrack.hasChannels()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":channels"), oneTrack.channels());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":channels"), {});
}
if (oneTrack.hasBitRate()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":bitRate"), oneTrack.bitRate());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":bitRate"), {});
}
if (oneTrack.hasSampleRate()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":sampleRate"), oneTrack.sampleRate());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":sampleRate"), {});
}
d->mInsertTrackQuery.bindValue(QStringLiteral(":hasEmbeddedCover"), oneTrack.hasEmbeddedCover());
if (!oneTrack.title().isEmpty()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":trackId"), existingTrackId);
d->mInsertTrackQuery.bindValue(QStringLiteral(":fileName"), oneTrack.resourceURI());
d->mInsertTrackQuery.bindValue(QStringLiteral(":priority"), priority);
d->mInsertTrackQuery.bindValue(QStringLiteral(":title"), oneTrack.title());
insertArtist(oneTrack.artist());
d->mInsertTrackQuery.bindValue(QStringLiteral(":artistName"), oneTrack.artist());
d->mInsertTrackQuery.bindValue(QStringLiteral(":albumTitle"), oneTrack.album());
if (oneTrack.hasAlbumArtist()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":albumArtistName"), oneTrack.albumArtist());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":albumArtistName"), {});
}
d->mInsertTrackQuery.bindValue(QStringLiteral(":albumPath"), trackPath);
if (oneTrack.hasTrackNumber()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":trackNumber"), oneTrack.trackNumber());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":trackNumber"), {});
}
if (oneTrack.hasDiscNumber()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":discNumber"), oneTrack.discNumber());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":discNumber"), {});
}
d->mInsertTrackQuery.bindValue(QStringLiteral(":trackDuration"), QVariant::fromValue<qlonglong>(oneTrack.duration().msecsSinceStartOfDay()));
d->mInsertTrackQuery.bindValue(QStringLiteral(":trackRating"), oneTrack.rating());
if (insertGenre(oneTrack.genre()) != 0) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":genre"), oneTrack.genre());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":genre"), {});
}
if (insertComposer(oneTrack.composer()) != 0) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":composer"), oneTrack.composer());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":composer"), {});
}
if (insertLyricist(oneTrack.lyricist()) != 0) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":lyricist"), oneTrack.lyricist());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":lyricist"), {});
}
d->mInsertTrackQuery.bindValue(QStringLiteral(":comment"), oneTrack.comment());
d->mInsertTrackQuery.bindValue(QStringLiteral(":year"), oneTrack.year());
if (oneTrack.hasChannels()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":channels"), oneTrack.channels());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":channels"), {});
}
if (oneTrack.hasBitRate()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":bitRate"), oneTrack.bitRate());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":bitRate"), {});
}
if (oneTrack.hasSampleRate()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":sampleRate"), oneTrack.sampleRate());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":sampleRate"), {});
}
d->mInsertTrackQuery.bindValue(QStringLiteral(":hasEmbeddedCover"), oneTrack.hasEmbeddedCover());
auto result = execQuery(d->mInsertTrackQuery);
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::internalInsertTrack" << oneTrack << "is inserted";
auto result = execQuery(d->mInsertTrackQuery);
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::internalInsertTrack" << oneTrack << "is inserted";
if (result && d->mInsertTrackQuery.isActive()) {
d->mInsertTrackQuery.finish();
if (result && d->mInsertTrackQuery.isActive()) {
d->mInsertTrackQuery.finish();
if (!isModifiedTrack) {
++d->mTrackId;
}
if (!isModifiedTrack) {
++d->mTrackId;
}
updateTrackOrigin(oneTrack.resourceURI(), oneTrack.fileModificationTime());
updateTrackOrigin(oneTrack.resourceURI(), oneTrack.fileModificationTime());
if (isModifiedTrack) {
recordModifiedTrack(existingTrackId);
if (albumId != 0) {
recordModifiedAlbum(albumId);
}
if (oldAlbumId != 0) {
recordModifiedAlbum(oldAlbumId);
if (isModifiedTrack) {
recordModifiedTrack(existingTrackId);
if (albumId != 0) {
recordModifiedAlbum(albumId);
}
if (oldAlbumId != 0) {
recordModifiedAlbum(oldAlbumId);
}
}
}
if (albumId != 0) {
if (updateAlbumFromId(albumId, covers[oneTrack.resourceURI().toString()], oneTrack, trackPath)) {
auto modifiedTracks = fetchTrackIds(albumId);
for (auto oneModifiedTrack : modifiedTracks) {
if (oneModifiedTrack != resultId) {
recordModifiedTrack(oneModifiedTrack);
if (albumId != 0) {
if (updateAlbumFromId(albumId, covers[oneTrack.resourceURI().toString()], oneTrack, trackPath)) {
auto modifiedTracks = fetchTrackIds(albumId);
for (auto oneModifiedTrack : modifiedTracks) {
if (oneModifiedTrack != resultId) {
recordModifiedTrack(oneModifiedTrack);
}
}
}
recordModifiedAlbum(albumId);
}
recordModifiedAlbum(albumId);
} else {
d->mInsertTrackQuery.finish();
Q_EMIT databaseError();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::internalInsertTrack" << oneTrack << oneTrack.resourceURI();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::internalInsertTrack" << d->mInsertTrackQuery.lastQuery();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::internalInsertTrack" << d->mInsertTrackQuery.boundValues();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::internalInsertTrack" << d->mInsertTrackQuery.lastError();
}
} else {
d->mInsertTrackQuery.finish();
Q_EMIT databaseError();
if (!isModifiedTrack) {
++d->mTrackId;
}
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::internalInsertTrack" << oneTrack << oneTrack.resourceURI();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::internalInsertTrack" << d->mInsertTrackQuery.lastQuery();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::internalInsertTrack" << d->mInsertTrackQuery.boundValues();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::internalInsertTrack" << d->mInsertTrackQuery.lastError();
updateTrackOrigin(oneTrack.resourceURI(), oneTrack.fileModificationTime());
}
return resultId;
......
......@@ -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>
......@@ -43,7 +45,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) {
......@@ -1017,6 +1023,8 @@ void MediaPlayList::tracksListAdded(qulonglong newDatabaseId,
void MediaPlayList::trackChanged(const TrackDataType &track)
{
qCDebug(orgKdeElisaPlayList()) << "MediaPlayList::trackChanged" << track[DataTypes::TitleRole];
for (int i = 0; i < d->mData.size(); ++i) {
auto &oneEntry = d->mData[i];
......
......@@ -126,8 +126,8 @@ public:
PlayFrequency,
ElementTypeRole,
LyricsRole,
FullDataRole,
IsValidRole,
TrackDataRole,
CountRole,
IsPlayingRole,
AlbumSectionRole,
......
......@@ -270,6 +270,7 @@ void ModelDataLoader::loadDataByUrl(ElisaUtils::PlayListEntryType dataType, cons