From af5a36f26a49eef374f95f1cec906170bc65f556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 11 Aug 2019 16:17:00 +0200 Subject: [PATCH 01/13] Remove unused unremove flag from addMultipleTracks() --- src/library/analysisfeature.cpp | 2 +- src/library/autodj/autodjfeature.cpp | 2 +- src/library/crate/cratefeature.cpp | 2 +- src/library/crate/cratetablemodel.cpp | 2 +- src/library/dao/trackdao.cpp | 46 ++++++++++++--------------- src/library/dao/trackdao.h | 2 +- src/library/librarytablemodel.cpp | 2 +- src/library/mixxxlibraryfeature.cpp | 2 +- src/library/playlistfeature.cpp | 2 +- src/library/playlisttablemodel.cpp | 2 +- 10 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/library/analysisfeature.cpp b/src/library/analysisfeature.cpp index 548c7c1f05c..ee9ee88834f 100644 --- a/src/library/analysisfeature.cpp +++ b/src/library/analysisfeature.cpp @@ -196,7 +196,7 @@ bool AnalysisFeature::dropAccept(QList urls, QObject* pSource) { Q_UNUSED(pSource); QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); // Adds track, does not insert duplicates, handles unremoving logic. - QList trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files, true); + QList trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files); analyzeTracks(trackIds); return trackIds.size() > 0; } diff --git a/src/library/autodj/autodjfeature.cpp b/src/library/autodj/autodjfeature.cpp index 0edbbbae7fa..f0ce44d49cd 100644 --- a/src/library/autodj/autodjfeature.cpp +++ b/src/library/autodj/autodjfeature.cpp @@ -147,7 +147,7 @@ bool AutoDJFeature::dropAccept(QList urls, QObject* pSource) { trackIds = m_pTrackCollection->getTrackDAO().getTrackIds(files); m_pTrackCollection->unhideTracks(trackIds); } else { - trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files, true); + trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files); } // remove tracks that could not be added diff --git a/src/library/crate/cratefeature.cpp b/src/library/crate/cratefeature.cpp index 5487ff36dc6..38ab09adb56 100644 --- a/src/library/crate/cratefeature.cpp +++ b/src/library/crate/cratefeature.cpp @@ -210,7 +210,7 @@ bool CrateFeature::dropAcceptChild(const QModelIndex& index, QList urls, m_pTrackCollection->unhideTracks(trackIds); } else { // Adds track, does not insert duplicates, handles unremoving logic. - trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files, true); + trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files); } qDebug() << "CrateFeature::dropAcceptChild adding tracks" << trackIds.size() << " to crate "<< crateId; diff --git a/src/library/crate/cratetablemodel.cpp b/src/library/crate/cratetablemodel.cpp index ca059ffe10a..7e808a4430b 100644 --- a/src/library/crate/cratetablemodel.cpp +++ b/src/library/crate/cratetablemodel.cpp @@ -154,7 +154,7 @@ int CrateTableModel::addTracks(const QModelIndex& index, } } - QList trackIds(m_pTrackCollection->getTrackDAO().addMultipleTracks(fileInfoList, true)); + QList trackIds(m_pTrackCollection->getTrackDAO().addMultipleTracks(fileInfoList)); if (m_pTrackCollection->addCrateTracks(m_selectedCrate, trackIds)) { select(); return trackIds.size(); diff --git a/src/library/dao/trackdao.cpp b/src/library/dao/trackdao.cpp index 282b05a86f7..39d439b4057 100644 --- a/src/library/dao/trackdao.cpp +++ b/src/library/dao/trackdao.cpp @@ -688,8 +688,7 @@ TrackPointer TrackDAO::addSingleTrack(const QFileInfo& fileInfo, bool unremove) } QList TrackDAO::addMultipleTracks( - const QList& fileInfoList, - bool unremove) { + const QList& fileInfoList) { // Prepare to add tracks to the database. // This also begins an SQL transaction. addTracksPrepare(); @@ -717,29 +716,26 @@ QList TrackDAO::addMultipleTracks( index++; } - // If imported-playlist tracks are to be unremoved, do that for all playlist - // tracks that were already in the database. - if (unremove) { - query.prepare("SELECT library.id FROM playlist_import, " - "track_locations, library WHERE library.location = track_locations.id " - "AND playlist_import.location = track_locations.location"); - if (!query.exec()) { - LOG_FAILED_QUERY(query); - } + // Unremove all playlist tracks, that were already in the database. + query.prepare("SELECT library.id FROM playlist_import, " + "track_locations, library WHERE library.location = track_locations.id " + "AND playlist_import.location = track_locations.location"); + if (!query.exec()) { + LOG_FAILED_QUERY(query); + } - int idColumn = query.record().indexOf("id"); - QStringList idStringList; - while (query.next()) { - TrackId trackId(query.value(idColumn)); - idStringList.append(trackId.toString()); - } + int idColumn = query.record().indexOf("id"); + QStringList idStringList; + while (query.next()) { + TrackId trackId(query.value(idColumn)); + idStringList.append(trackId.toString()); + } - query.prepare(QString("UPDATE library SET mixxx_deleted=0 " - "WHERE id in (%1) AND mixxx_deleted=1") - .arg(idStringList.join(","))); - if (!query.exec()) { - LOG_FAILED_QUERY(query); - } + query.prepare(QString("UPDATE library SET mixxx_deleted=0 " + "WHERE id in (%1) AND mixxx_deleted=1") + .arg(idStringList.join(","))); + if (!query.exec()) { + LOG_FAILED_QUERY(query); } // Any tracks not already in the database need to be added. @@ -753,7 +749,7 @@ QList TrackDAO::addMultipleTracks( while (query.next()) { int addIndex = query.value(addIndexColumn).toInt(); const QFileInfo fileInfo(fileInfoList.at(addIndex)); - addTracksAddFile(fileInfo, unremove); + addTracksAddFile(fileInfo, true); } // Now that we have imported any tracks that were not already in the @@ -768,7 +764,7 @@ QList TrackDAO::addMultipleTracks( if (!query.exec()) { LOG_FAILED_QUERY(query); } - int idColumn = query.record().indexOf("id"); + idColumn = query.record().indexOf("id"); while (query.next()) { TrackId trackId(query.value(idColumn)); trackIds.append(trackId); diff --git a/src/library/dao/trackdao.h b/src/library/dao/trackdao.h index f3ce490ccad..76549c7446a 100644 --- a/src/library/dao/trackdao.h +++ b/src/library/dao/trackdao.h @@ -51,7 +51,7 @@ class TrackDAO : public QObject, public virtual DAO, public virtual GlobalTrackC QString getTrackLocation(TrackId trackId); TrackPointer addSingleTrack(const QFileInfo& fileInfo, bool unremove); - QList addMultipleTracks(const QList& fileInfoList, bool unremove); + QList addMultipleTracks(const QList& fileInfoList); void addTracksPrepare(); TrackPointer addTracksAddFile(const QFileInfo& fileInfo, bool unremove); diff --git a/src/library/librarytablemodel.cpp b/src/library/librarytablemodel.cpp index 3d79457bea5..f4a4c838e76 100644 --- a/src/library/librarytablemodel.cpp +++ b/src/library/librarytablemodel.cpp @@ -65,7 +65,7 @@ int LibraryTableModel::addTracks(const QModelIndex& index, foreach (QString fileLocation, locations) { fileInfoList.append(QFileInfo(fileLocation)); } - QList trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(fileInfoList, true); + QList trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(fileInfoList); select(); return trackIds.size(); } diff --git a/src/library/mixxxlibraryfeature.cpp b/src/library/mixxxlibraryfeature.cpp index 199a2926df4..36323c4f105 100644 --- a/src/library/mixxxlibraryfeature.cpp +++ b/src/library/mixxxlibraryfeature.cpp @@ -184,7 +184,7 @@ bool MixxxLibraryFeature::dropAccept(QList urls, QObject* pSource) { QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); // Adds track, does not insert duplicates, handles unremoving logic. - QList trackIds = m_trackDao.addMultipleTracks(files, true); + QList trackIds = m_trackDao.addMultipleTracks(files); return trackIds.size() > 0; } } diff --git a/src/library/playlistfeature.cpp b/src/library/playlistfeature.cpp index 197f57fb76d..2266769f02d 100644 --- a/src/library/playlistfeature.cpp +++ b/src/library/playlistfeature.cpp @@ -116,7 +116,7 @@ bool PlaylistFeature::dropAcceptChild(const QModelIndex& index, QList urls // library, then add the track to the library before adding it to the // playlist. // Adds track, does not insert duplicates, handles unremoving logic. - trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files, true); + trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files); } // remove tracks that could not be added diff --git a/src/library/playlisttablemodel.cpp b/src/library/playlisttablemodel.cpp index e1bc686c7d3..c6bc0d48a3b 100644 --- a/src/library/playlisttablemodel.cpp +++ b/src/library/playlisttablemodel.cpp @@ -94,7 +94,7 @@ int PlaylistTableModel::addTracks(const QModelIndex& index, } } - QList trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(fileInfoList, true); + QList trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(fileInfoList); int tracksAdded = m_pTrackCollection->getPlaylistDAO().insertTracksIntoPlaylist( trackIds, m_iPlaylistId, position); From 5ad6d78b831d490072e705cc0aef52ea411aab81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 11 Aug 2019 16:22:22 +0200 Subject: [PATCH 02/13] Remove superfluid transaction around a single sql statment, which was an a wron application layer anyway. --- src/library/dao/trackdao.cpp | 2 +- src/library/dao/trackdao.h | 2 +- src/library/trackcollection.cpp | 10 +--------- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/library/dao/trackdao.cpp b/src/library/dao/trackdao.cpp index 39d439b4057..a16135d3195 100644 --- a/src/library/dao/trackdao.cpp +++ b/src/library/dao/trackdao.cpp @@ -807,7 +807,7 @@ void TrackDAO::afterHidingTracks( // up in the library views again. // This function should get called if you drag-and-drop a file that's been // "hidden" from Mixxx back into the library view. -bool TrackDAO::onUnhidingTracks( +bool TrackDAO::unhideTracks( const QList& trackIds) { QStringList idList; for (const auto& trackId: trackIds) { diff --git a/src/library/dao/trackdao.h b/src/library/dao/trackdao.h index 76549c7446a..e67a23ec749 100644 --- a/src/library/dao/trackdao.h +++ b/src/library/dao/trackdao.h @@ -63,7 +63,7 @@ class TrackDAO : public QObject, public virtual DAO, public virtual GlobalTrackC void afterHidingTracks( const QList& trackIds); - bool onUnhidingTracks( + bool unhideTracks( const QList& trackIds); void afterUnhidingTracks( const QList& trackIds); diff --git a/src/library/trackcollection.cpp b/src/library/trackcollection.cpp index 62c0b64ab4c..b652d013e18 100644 --- a/src/library/trackcollection.cpp +++ b/src/library/trackcollection.cpp @@ -156,15 +156,7 @@ bool TrackCollection::hideTracks(const QList& trackIds) { bool TrackCollection::unhideTracks(const QList& trackIds) { DEBUG_ASSERT(QApplication::instance()->thread() == QThread::currentThread()); - // Transactional - SqlTransaction transaction(m_database); - VERIFY_OR_DEBUG_ASSERT(transaction) { - return false; - } - VERIFY_OR_DEBUG_ASSERT(m_trackDao.onUnhidingTracks(trackIds)) { - return false; - } - VERIFY_OR_DEBUG_ASSERT(transaction.commit()) { + VERIFY_OR_DEBUG_ASSERT(m_trackDao.unhideTracks(trackIds)) { return false; } From 901095c3a513eb542f983f0b64b98a1c696c0f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 11 Aug 2019 23:27:37 +0200 Subject: [PATCH 03/13] introduce new function getAndEnsureTrackIds() --- src/library/autodj/autodjfeature.cpp | 3 +-- src/library/crate/cratefeature.cpp | 3 +-- src/library/playlistfeature.cpp | 3 +-- src/library/trackcollection.cpp | 14 ++++++++++++-- src/library/trackcollection.h | 4 ++++ 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/library/autodj/autodjfeature.cpp b/src/library/autodj/autodjfeature.cpp index f0ce44d49cd..798e30f8a20 100644 --- a/src/library/autodj/autodjfeature.cpp +++ b/src/library/autodj/autodjfeature.cpp @@ -144,8 +144,7 @@ bool AutoDJFeature::dropAccept(QList urls, QObject* pSource) { QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); QList trackIds; if (pSource) { - trackIds = m_pTrackCollection->getTrackDAO().getTrackIds(files); - m_pTrackCollection->unhideTracks(trackIds); + trackIds = m_pTrackCollection->getAndEnsureTrackIds(files); } else { trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files); } diff --git a/src/library/crate/cratefeature.cpp b/src/library/crate/cratefeature.cpp index 38ab09adb56..f59f7f4f56a 100644 --- a/src/library/crate/cratefeature.cpp +++ b/src/library/crate/cratefeature.cpp @@ -206,8 +206,7 @@ bool CrateFeature::dropAcceptChild(const QModelIndex& index, QList urls, QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); QList trackIds; if (pSource) { - trackIds = m_pTrackCollection->getTrackDAO().getTrackIds(files); - m_pTrackCollection->unhideTracks(trackIds); + trackIds = m_pTrackCollection->getAndEnsureTrackIds(files); } else { // Adds track, does not insert duplicates, handles unremoving logic. trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files); diff --git a/src/library/playlistfeature.cpp b/src/library/playlistfeature.cpp index 2266769f02d..73644efea63 100644 --- a/src/library/playlistfeature.cpp +++ b/src/library/playlistfeature.cpp @@ -109,8 +109,7 @@ bool PlaylistFeature::dropAcceptChild(const QModelIndex& index, QList urls QList trackIds; if (pSource) { - trackIds = m_pTrackCollection->getTrackDAO().getTrackIds(files); - m_pTrackCollection->unhideTracks(trackIds); + trackIds = m_pTrackCollection->getAndEnsureTrackIds(files); } else { // If a track is dropped onto a playlist's name, but the track isn't in the // library, then add the track to the library before adding it to the diff --git a/src/library/trackcollection.cpp b/src/library/trackcollection.cpp index b652d013e18..314b46d97b0 100644 --- a/src/library/trackcollection.cpp +++ b/src/library/trackcollection.cpp @@ -87,6 +87,13 @@ void TrackCollection::relocateDirectory(QString oldDir, QString newDir) { GlobalTrackCacheLocker().relocateCachedTracks(&m_trackDao); } +QList TrackCollection::getAndEnsureTrackIds( + const QList& files) { + QList trackIds = m_trackDao.getTrackIds(files); + unhideTracks(trackIds); + return trackIds; +} + bool TrackCollection::hideTracks(const QList& trackIds) { DEBUG_ASSERT(QApplication::instance()->thread() == QThread::currentThread()); @@ -162,13 +169,16 @@ bool TrackCollection::unhideTracks(const QList& trackIds) { // Post-processing // TODO(XXX): Move signals from TrackDAO to TrackCollection + // To update BaseTrackCache m_trackDao.afterUnhidingTracks(trackIds); // TODO(XXX): Move signals from TrackDAO to TrackCollection // Emit signal(s) // TODO(XXX): Emit signals here instead of from DAOs - QSet modifiedCrateSummaries( - m_crates.collectCrateIdsOfTracks(trackIds)); + // To update labels of CrateFeature, because unhiding might make a + // crate track visible again. + QSet modifiedCrateSummaries = + m_crates.collectCrateIdsOfTracks(trackIds); emit(crateSummaryChanged(modifiedCrateSummaries)); return true; diff --git a/src/library/trackcollection.h b/src/library/trackcollection.h index eefd00bb9a7..ed63a8b4b86 100644 --- a/src/library/trackcollection.h +++ b/src/library/trackcollection.h @@ -66,6 +66,10 @@ class TrackCollection : public QObject, void relocateDirectory(QString oldDir, QString newDir); + // This function returns a track ID of all file in the list not already visible, + // it adds and unhides the tracks as well. + QList getAndEnsureTrackIds(const QList& files); + bool hideTracks(const QList& trackIds); bool unhideTracks(const QList& trackIds); From 0e9b7272de191aed85cb7ea8aae2b539860a7a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Mon, 12 Aug 2019 18:36:36 +0200 Subject: [PATCH 04/13] Use a temp table to keep sorting unchanged in TrackDAO::getTrackIds() --- src/library/dao/trackdao.cpp | 53 +++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/src/library/dao/trackdao.cpp b/src/library/dao/trackdao.cpp index a16135d3195..9b1c4d6f553 100644 --- a/src/library/dao/trackdao.cpp +++ b/src/library/dao/trackdao.cpp @@ -139,18 +139,45 @@ QList TrackDAO::getTrackIds(const QList& files) { QList trackIds; trackIds.reserve(files.size()); + // Create a temporary database of the paths of all the imported tracks. QSqlQuery query(m_database); - { - QStringList pathList; - pathList.reserve(files.size()); - for (const auto& file: files) { - pathList << file.absoluteFilePath(); - } - query.prepare(QString("SELECT library.id FROM library INNER JOIN " - "track_locations ON library.location = track_locations.id " - "WHERE track_locations.location in (%1)").arg( - SqlStringFormatter::formatList(m_database, pathList))); + query.prepare( + "CREATE TEMP TABLE playlist_import " + "(location varchar (512))"); + if (!query.exec()) { + LOG_FAILED_QUERY(query); + return trackIds; + } + + QStringList pathList; + pathList.reserve(files.size()); + for (const auto& file: files) { + pathList << "(" + SqlStringFormatter::format(m_database, file.absoluteFilePath()) + ")"; + } + + // Add all the track paths temporary to this database. + query.prepare( + "INSERT INTO playlist_import (location) " + "VALUES " + pathList.join(',')); + if (!query.exec()) { + LOG_FAILED_QUERY(query); } + + query.prepare( + "SELECT library.id FROM playlist_import " + "INNER JOIN track_locations ON playlist_import.location = track_locations.location " + "INNER JOIN library ON library.location = track_locations.id " + // the order by clause enforces the native sorting which is used anyway + // hopefully optimized away. TODO() verify. + "ORDER BY playlist_import.ROWID"); + + // Old syntax for a shorter but less readable query. TODO() check performance gain + // query.prepare( + // "SELECT library.id FROM playlist_import, " + // "track_locations, library WHERE library.location = track_locations.id " + // "AND playlist_import.location = track_locations.location"); + // "ORDER BY playlist_import.ROWID"); + if (query.exec()) { const int idColumn = query.record().indexOf("id"); while (query.next()) { @@ -164,6 +191,12 @@ QList TrackDAO::getTrackIds(const QList& files) { LOG_FAILED_QUERY(query); } + // Drop the temporary playlist-import table. + query.prepare("DROP TABLE IF EXISTS playlist_import"); + if (!query.exec()) { + LOG_FAILED_QUERY(query); + } + return trackIds; } From af85c1c4e5b3584402095c85e760b83cb476ffc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Mon, 12 Aug 2019 23:32:52 +0200 Subject: [PATCH 05/13] Improve query in TrackDAO::unhideTracks() --- src/library/dao/trackdao.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/library/dao/trackdao.cpp b/src/library/dao/trackdao.cpp index 9b1c4d6f553..30f761ad985 100644 --- a/src/library/dao/trackdao.cpp +++ b/src/library/dao/trackdao.cpp @@ -846,9 +846,10 @@ bool TrackDAO::unhideTracks( for (const auto& trackId: trackIds) { idList.append(trackId.toString()); } - FwdSqlQuery query(m_database, QString( + FwdSqlQuery query(m_database, "UPDATE library SET mixxx_deleted=0 " - "WHERE id in (%1)").arg(idList.join(","))); + "WHERE mixxx_deleted!=0 " + "AND id in (" + idList.join(",") + ")"); return !query.hasError() && query.execPrepared(); } From 5eb8ac0f398e0c81a967e9b0403e9ec52c339d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Tue, 13 Aug 2019 01:35:27 +0200 Subject: [PATCH 06/13] Add the addMissingTracks fature to TrackDAO::getTrackIds() and make use of it. --- src/library/autodj/autodjfeature.cpp | 27 ++++++++++++------------ src/library/crate/cratefeature.cpp | 31 ++++++++++++++-------------- src/library/dao/trackdao.cpp | 26 ++++++++++++++++++++++- src/library/dao/trackdao.h | 2 +- src/library/playlistfeature.cpp | 31 ++++++++++++++-------------- src/library/trackcollection.cpp | 4 ++-- src/library/trackcollection.h | 2 +- 7 files changed, 73 insertions(+), 50 deletions(-) diff --git a/src/library/autodj/autodjfeature.cpp b/src/library/autodj/autodjfeature.cpp index 798e30f8a20..6387c8a27a7 100644 --- a/src/library/autodj/autodjfeature.cpp +++ b/src/library/autodj/autodjfeature.cpp @@ -138,25 +138,24 @@ void AutoDJFeature::activate() { } bool AutoDJFeature::dropAccept(QList urls, QObject* pSource) { - // If a track is dropped onto a playlist's name, but the track isn't in the - // library, then add the track to the library before adding it to the - // playlist. QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); - QList trackIds; - if (pSource) { - trackIds = m_pTrackCollection->getAndEnsureTrackIds(files); - } else { - trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files); + if (!files.size()) { + return false; } - // remove tracks that could not be added - for (int trackIdIndex = 0; trackIdIndex < trackIds.size(); trackIdIndex++) { - if (!trackIds.at(trackIdIndex).isValid()) { - trackIds.removeAt(trackIdIndex--); - } + // If a track is dropped onto the Auto DJ tree node, but the track isn't in the + // library, then add the track to the library before adding it to the + // Auto DJ playlist. getAndEnsureTrackIds(), does not insert duplicates and handles + // unremove logic. + // pSource != nullptr it is a drop from inside Mixxx and indicates all + // tracks already in the DB + bool addMissingTracks = (pSource == nullptr); + QList trackIds = m_pTrackCollection->getAndEnsureTrackIds(files, addMissingTracks); + if (!trackIds.size()) { + return false; } - // Return whether the tracks were appended. + // Return whether appendTracksToPlaylist succeeded. return m_playlistDao.appendTracksToPlaylist(trackIds, m_iAutoDJPlaylistId); } diff --git a/src/library/crate/cratefeature.cpp b/src/library/crate/cratefeature.cpp index f59f7f4f56a..1dbd770fef8 100644 --- a/src/library/crate/cratefeature.cpp +++ b/src/library/crate/cratefeature.cpp @@ -200,25 +200,26 @@ void updateTreeItemForTrackSelection( bool CrateFeature::dropAcceptChild(const QModelIndex& index, QList urls, QObject* pSource) { CrateId crateId(crateIdFromIndex(index)); - if (!crateId.isValid()) { + VERIFY_OR_DEBUG_ASSERT(crateId.isValid()) { return false; } QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); - QList trackIds; - if (pSource) { - trackIds = m_pTrackCollection->getAndEnsureTrackIds(files); - } else { - // Adds track, does not insert duplicates, handles unremoving logic. - trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files); - } - qDebug() << "CrateFeature::dropAcceptChild adding tracks" - << trackIds.size() << " to crate "<< crateId; - // remove tracks that could not be added - for (int trackIdIndex = 0; trackIdIndex < trackIds.size(); ++trackIdIndex) { - if (!trackIds.at(trackIdIndex).isValid()) { - trackIds.removeAt(trackIdIndex--); - } + if (!files.size()) { + return false; } + + // If a track is dropped onto a crate's name, but the track isn't in the + // library, then add the track to the library before adding it to the + // playlist. getAndEnsureTrackIds(), does not insert duplicates and handles + // unremove logic. + // pSource != nullptr it is a drop from inside Mixxx and indicates all + // tracks already in the DB + bool addMissingTracks = (pSource == nullptr); + QList trackIds = m_pTrackCollection->getAndEnsureTrackIds(files, addMissingTracks); + if (!trackIds.size()) { + return false; + } + m_pTrackCollection->addCrateTracks(crateId, trackIds); return true; } diff --git a/src/library/dao/trackdao.cpp b/src/library/dao/trackdao.cpp index 30f761ad985..1189e6827f4 100644 --- a/src/library/dao/trackdao.cpp +++ b/src/library/dao/trackdao.cpp @@ -135,7 +135,8 @@ TrackId TrackDAO::getTrackId(const QString& absoluteFilePath) { return trackId; } -QList TrackDAO::getTrackIds(const QList& files) { +QList TrackDAO::getTrackIds(const QList& files, + bool addMissingTracks) { QList trackIds; trackIds.reserve(files.size()); @@ -163,6 +164,29 @@ QList TrackDAO::getTrackIds(const QList& files) { LOG_FAILED_QUERY(query); } + if (addMissingTracks) { + // Prepare to add tracks to the database. + // This also begins an SQL transaction. + addTracksPrepare(); + + // Any tracks not already in the database need to be added. + query.prepare("SELECT location FROM playlist_import " + "WHERE NOT EXISTS (SELECT location FROM track_locations " + "WHERE playlist_import.location = track_locations.location)"); + if (!query.exec()) { + LOG_FAILED_QUERY(query); + } + const int locationColumn = query.record().indexOf("location"); + while (query.next()) { + QString location = query.value(locationColumn).toString(); + const QFileInfo fileInfo(location); + addTracksAddFile(fileInfo, true); + } + + // Finish adding tracks to the database. + addTracksFinish(); + } + query.prepare( "SELECT library.id FROM playlist_import " "INNER JOIN track_locations ON playlist_import.location = track_locations.location " diff --git a/src/library/dao/trackdao.h b/src/library/dao/trackdao.h index e67a23ec749..3abfebf7ab5 100644 --- a/src/library/dao/trackdao.h +++ b/src/library/dao/trackdao.h @@ -40,7 +40,7 @@ class TrackDAO : public QObject, public virtual DAO, public virtual GlobalTrackC void finish(); TrackId getTrackId(const QString& absoluteFilePath); - QList getTrackIds(const QList& files); + QList getTrackIds(const QList& files, bool addMissingTracks); QList getTrackIds(const QDir& dir); // WARNING: Only call this from the main thread instance of TrackDAO. diff --git a/src/library/playlistfeature.cpp b/src/library/playlistfeature.cpp index 73644efea63..0966fc8b433 100644 --- a/src/library/playlistfeature.cpp +++ b/src/library/playlistfeature.cpp @@ -103,26 +103,25 @@ void PlaylistFeature::onRightClickChild(const QPoint& globalPos, QModelIndex ind bool PlaylistFeature::dropAcceptChild(const QModelIndex& index, QList urls, QObject* pSource) { int playlistId = playlistIdFromIndex(index); - //m_playlistDao.appendTrackToPlaylist(url.toLocalFile(), playlistId); + VERIFY_OR_DEBUG_ASSERT(playlistId >= 0) { + return false; + } QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); - - QList trackIds; - if (pSource) { - trackIds = m_pTrackCollection->getAndEnsureTrackIds(files); - } else { - // If a track is dropped onto a playlist's name, but the track isn't in the - // library, then add the track to the library before adding it to the - // playlist. - // Adds track, does not insert duplicates, handles unremoving logic. - trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files); + if (!files.size()) { + return false; } - // remove tracks that could not be added - for (int trackIdIndex = 0; trackIdIndex < trackIds.size(); ++trackIdIndex) { - if (!trackIds.at(trackIdIndex).isValid()) { - trackIds.removeAt(trackIdIndex--); - } + // If a track is dropped onto a playlist's name, but the track isn't in the + // library, then add the track to the library before adding it to the + // playlist. getAndEnsureTrackIds(), does not insert duplicates and handles + // unremove logic. + // pSource != nullptr it is a drop from inside Mixxx and indicates all + // tracks already in the DB + bool addMissingTracks = (pSource == nullptr); + QList trackIds = m_pTrackCollection->getAndEnsureTrackIds(files, addMissingTracks); + if (!trackIds.size()) { + return false; } // Return whether appendTracksToPlaylist succeeded. diff --git a/src/library/trackcollection.cpp b/src/library/trackcollection.cpp index 314b46d97b0..ff68351687c 100644 --- a/src/library/trackcollection.cpp +++ b/src/library/trackcollection.cpp @@ -88,8 +88,8 @@ void TrackCollection::relocateDirectory(QString oldDir, QString newDir) { } QList TrackCollection::getAndEnsureTrackIds( - const QList& files) { - QList trackIds = m_trackDao.getTrackIds(files); + const QList& files, bool addMissingTracks) { + QList trackIds = m_trackDao.getTrackIds(files, addMissingTracks); unhideTracks(trackIds); return trackIds; } diff --git a/src/library/trackcollection.h b/src/library/trackcollection.h index ed63a8b4b86..c880ae54edd 100644 --- a/src/library/trackcollection.h +++ b/src/library/trackcollection.h @@ -68,7 +68,7 @@ class TrackCollection : public QObject, // This function returns a track ID of all file in the list not already visible, // it adds and unhides the tracks as well. - QList getAndEnsureTrackIds(const QList& files); + QList getAndEnsureTrackIds(const QList& files, bool addMissingTracks); bool hideTracks(const QList& trackIds); bool unhideTracks(const QList& trackIds); From acb844454ea098c89a3aa72a72196b4fcbd17219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Tue, 13 Aug 2019 02:13:23 +0200 Subject: [PATCH 07/13] Completely replace obsolete TrackDAO::addMultipleTracks() calls by getAndEnsureTrackIds() --- src/library/analysisfeature.cpp | 2 +- src/library/crate/cratetablemodel.cpp | 6 +- src/library/dao/trackdao.cpp | 96 --------------------------- src/library/dao/trackdao.h | 2 - src/library/librarytablemodel.cpp | 2 +- src/library/mixxxlibraryfeature.cpp | 2 +- src/library/playlisttablemodel.cpp | 8 +-- 7 files changed, 8 insertions(+), 110 deletions(-) diff --git a/src/library/analysisfeature.cpp b/src/library/analysisfeature.cpp index ee9ee88834f..39ac2d3cf64 100644 --- a/src/library/analysisfeature.cpp +++ b/src/library/analysisfeature.cpp @@ -196,7 +196,7 @@ bool AnalysisFeature::dropAccept(QList urls, QObject* pSource) { Q_UNUSED(pSource); QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); // Adds track, does not insert duplicates, handles unremoving logic. - QList trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files); + QList trackIds = m_pTrackCollection->getAndEnsureTrackIds(files, true); analyzeTracks(trackIds); return trackIds.size() > 0; } diff --git a/src/library/crate/cratetablemodel.cpp b/src/library/crate/cratetablemodel.cpp index 7e808a4430b..ef3e5e57df9 100644 --- a/src/library/crate/cratetablemodel.cpp +++ b/src/library/crate/cratetablemodel.cpp @@ -149,12 +149,10 @@ int CrateTableModel::addTracks(const QModelIndex& index, QList fileInfoList; foreach(QString fileLocation, locations) { QFileInfo fileInfo(fileLocation); - if (fileInfo.exists()) { - fileInfoList.append(fileInfo); - } + fileInfoList.append(fileInfo); } - QList trackIds(m_pTrackCollection->getTrackDAO().addMultipleTracks(fileInfoList)); + QList trackIds = m_pTrackCollection->getAndEnsureTrackIds(fileInfoList, true); if (m_pTrackCollection->addCrateTracks(m_selectedCrate, trackIds)) { select(); return trackIds.size(); diff --git a/src/library/dao/trackdao.cpp b/src/library/dao/trackdao.cpp index 1189e6827f4..d15fe064ceb 100644 --- a/src/library/dao/trackdao.cpp +++ b/src/library/dao/trackdao.cpp @@ -744,102 +744,6 @@ TrackPointer TrackDAO::addSingleTrack(const QFileInfo& fileInfo, bool unremove) return pTrack; } -QList TrackDAO::addMultipleTracks( - const QList& fileInfoList) { - // Prepare to add tracks to the database. - // This also begins an SQL transaction. - addTracksPrepare(); - - // Create a temporary database of the paths of all the imported tracks. - QSqlQuery query(m_database); - query.prepare("CREATE TEMP TABLE playlist_import " - "(add_index INTEGER PRIMARY KEY, location varchar (512))"); - if (!query.exec()) { - LOG_FAILED_QUERY(query); - addTracksFinish(true); - return QList(); - } - - // Add all the track paths to this database. - query.prepare("INSERT INTO playlist_import (add_index, location) " - "VALUES (:add_index, :location)"); - int index = 0; - for (const auto& fileInfo: fileInfoList) { - query.bindValue(":add_index", index); - query.bindValue(":location", fileInfo.absoluteFilePath()); - if (!query.exec()) { - LOG_FAILED_QUERY(query); - } - index++; - } - - // Unremove all playlist tracks, that were already in the database. - query.prepare("SELECT library.id FROM playlist_import, " - "track_locations, library WHERE library.location = track_locations.id " - "AND playlist_import.location = track_locations.location"); - if (!query.exec()) { - LOG_FAILED_QUERY(query); - } - - int idColumn = query.record().indexOf("id"); - QStringList idStringList; - while (query.next()) { - TrackId trackId(query.value(idColumn)); - idStringList.append(trackId.toString()); - } - - query.prepare(QString("UPDATE library SET mixxx_deleted=0 " - "WHERE id in (%1) AND mixxx_deleted=1") - .arg(idStringList.join(","))); - if (!query.exec()) { - LOG_FAILED_QUERY(query); - } - - // Any tracks not already in the database need to be added. - query.prepare("SELECT add_index, location FROM playlist_import " - "WHERE NOT EXISTS (SELECT location FROM track_locations " - "WHERE playlist_import.location = track_locations.location)"); - if (!query.exec()) { - LOG_FAILED_QUERY(query); - } - const int addIndexColumn = query.record().indexOf("add_index"); - while (query.next()) { - int addIndex = query.value(addIndexColumn).toInt(); - const QFileInfo fileInfo(fileInfoList.at(addIndex)); - addTracksAddFile(fileInfo, true); - } - - // Now that we have imported any tracks that were not already in the - // library, re-select ordering by playlist_import.add_index to return - // the list of track ids in the order that they were requested to be - // added. - QList trackIds; - query.prepare("SELECT library.id FROM playlist_import, " - "track_locations, library WHERE library.location = track_locations.id " - "AND playlist_import.location = track_locations.location " - "ORDER BY playlist_import.add_index"); - if (!query.exec()) { - LOG_FAILED_QUERY(query); - } - idColumn = query.record().indexOf("id"); - while (query.next()) { - TrackId trackId(query.value(idColumn)); - trackIds.append(trackId); - } - - // Drop the temporary playlist-import table. - query.prepare("DROP TABLE IF EXISTS playlist_import"); - if (!query.exec()) { - LOG_FAILED_QUERY(query); - } - - // Finish adding tracks to the database. - addTracksFinish(); - - // Return the list of track IDs added to the database. - return trackIds; -} - bool TrackDAO::onHidingTracks( const QList& trackIds) { QStringList idList; diff --git a/src/library/dao/trackdao.h b/src/library/dao/trackdao.h index 3abfebf7ab5..52824ad0301 100644 --- a/src/library/dao/trackdao.h +++ b/src/library/dao/trackdao.h @@ -51,8 +51,6 @@ class TrackDAO : public QObject, public virtual DAO, public virtual GlobalTrackC QString getTrackLocation(TrackId trackId); TrackPointer addSingleTrack(const QFileInfo& fileInfo, bool unremove); - QList addMultipleTracks(const QList& fileInfoList); - void addTracksPrepare(); TrackPointer addTracksAddFile(const QFileInfo& fileInfo, bool unremove); TrackId addTracksAddTrack(const TrackPointer& pTrack, bool unremove); diff --git a/src/library/librarytablemodel.cpp b/src/library/librarytablemodel.cpp index f4a4c838e76..5805125c15c 100644 --- a/src/library/librarytablemodel.cpp +++ b/src/library/librarytablemodel.cpp @@ -65,7 +65,7 @@ int LibraryTableModel::addTracks(const QModelIndex& index, foreach (QString fileLocation, locations) { fileInfoList.append(QFileInfo(fileLocation)); } - QList trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(fileInfoList); + QList trackIds = m_pTrackCollection->getAndEnsureTrackIds(fileInfoList, true); select(); return trackIds.size(); } diff --git a/src/library/mixxxlibraryfeature.cpp b/src/library/mixxxlibraryfeature.cpp index 36323c4f105..7eb29f42a4d 100644 --- a/src/library/mixxxlibraryfeature.cpp +++ b/src/library/mixxxlibraryfeature.cpp @@ -184,7 +184,7 @@ bool MixxxLibraryFeature::dropAccept(QList urls, QObject* pSource) { QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); // Adds track, does not insert duplicates, handles unremoving logic. - QList trackIds = m_trackDao.addMultipleTracks(files); + QList trackIds = m_pTrackCollection->getAndEnsureTrackIds(files, true); return trackIds.size() > 0; } } diff --git a/src/library/playlisttablemodel.cpp b/src/library/playlisttablemodel.cpp index c6bc0d48a3b..3b419f889aa 100644 --- a/src/library/playlisttablemodel.cpp +++ b/src/library/playlisttablemodel.cpp @@ -89,15 +89,13 @@ int PlaylistTableModel::addTracks(const QModelIndex& index, QList fileInfoList; foreach (QString fileLocation, locations) { QFileInfo fileInfo(fileLocation); - if (fileInfo.exists()) { - fileInfoList.append(fileInfo); - } + fileInfoList.append(fileInfo); } - QList trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(fileInfoList); + QList trackIds = m_pTrackCollection->getAndEnsureTrackIds(fileInfoList, true); int tracksAdded = m_pTrackCollection->getPlaylistDAO().insertTracksIntoPlaylist( - trackIds, m_iPlaylistId, position); + trackIds, m_iPlaylistId, position); if (locations.size() - tracksAdded > 0) { qDebug() << "PlaylistTableModel::addTracks could not add" From 29b81a7e58a9ac93acedb4f153308e1e2c8f8cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 18 Aug 2019 12:43:18 +0200 Subject: [PATCH 08/13] Renamed resolveTrackIds() and add enum fag option parameter --- src/library/analysisfeature.cpp | 5 +++-- src/library/autodj/autodjfeature.cpp | 10 ++++++---- src/library/crate/cratefeature.cpp | 10 ++++++---- src/library/crate/cratetablemodel.cpp | 4 +++- src/library/dao/trackdao.cpp | 6 +++--- src/library/dao/trackdao.h | 13 ++++++++++++- src/library/librarytablemodel.cpp | 4 +++- src/library/mixxxlibraryfeature.cpp | 6 +++--- src/library/playlistfeature.cpp | 10 ++++++---- src/library/playlisttablemodel.cpp | 4 +++- src/library/trackcollection.cpp | 10 ++++++---- src/library/trackcollection.h | 2 +- 12 files changed, 55 insertions(+), 29 deletions(-) diff --git a/src/library/analysisfeature.cpp b/src/library/analysisfeature.cpp index 39ac2d3cf64..058b7bc23e8 100644 --- a/src/library/analysisfeature.cpp +++ b/src/library/analysisfeature.cpp @@ -195,8 +195,9 @@ void AnalysisFeature::cleanupAnalyzer() { bool AnalysisFeature::dropAccept(QList urls, QObject* pSource) { Q_UNUSED(pSource); QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); - // Adds track, does not insert duplicates, handles unremoving logic. - QList trackIds = m_pTrackCollection->getAndEnsureTrackIds(files, true); + QList trackIds = m_pTrackCollection->resolveTrackIds(files, + TrackDAO::ResolveTrackIdOption::UnhideHidden + | TrackDAO::ResolveTrackIdOption::AddMissing); analyzeTracks(trackIds); return trackIds.size() > 0; } diff --git a/src/library/autodj/autodjfeature.cpp b/src/library/autodj/autodjfeature.cpp index 6387c8a27a7..1d4eed271fa 100644 --- a/src/library/autodj/autodjfeature.cpp +++ b/src/library/autodj/autodjfeature.cpp @@ -145,12 +145,14 @@ bool AutoDJFeature::dropAccept(QList urls, QObject* pSource) { // If a track is dropped onto the Auto DJ tree node, but the track isn't in the // library, then add the track to the library before adding it to the - // Auto DJ playlist. getAndEnsureTrackIds(), does not insert duplicates and handles - // unremove logic. + // Auto DJ playlist. // pSource != nullptr it is a drop from inside Mixxx and indicates all // tracks already in the DB - bool addMissingTracks = (pSource == nullptr); - QList trackIds = m_pTrackCollection->getAndEnsureTrackIds(files, addMissingTracks); + TrackDAO::ResolveTrackIdOptions options = TrackDAO::ResolveTrackIdOption::UnhideHidden; + if (pSource == nullptr) { + options |= TrackDAO::ResolveTrackIdOption::AddMissing; + } + QList trackIds = m_pTrackCollection->resolveTrackIds(files, options); if (!trackIds.size()) { return false; } diff --git a/src/library/crate/cratefeature.cpp b/src/library/crate/cratefeature.cpp index 1dbd770fef8..14d375b6e9b 100644 --- a/src/library/crate/cratefeature.cpp +++ b/src/library/crate/cratefeature.cpp @@ -210,12 +210,14 @@ bool CrateFeature::dropAcceptChild(const QModelIndex& index, QList urls, // If a track is dropped onto a crate's name, but the track isn't in the // library, then add the track to the library before adding it to the - // playlist. getAndEnsureTrackIds(), does not insert duplicates and handles - // unremove logic. + // playlist. // pSource != nullptr it is a drop from inside Mixxx and indicates all // tracks already in the DB - bool addMissingTracks = (pSource == nullptr); - QList trackIds = m_pTrackCollection->getAndEnsureTrackIds(files, addMissingTracks); + TrackDAO::ResolveTrackIdOptions options = TrackDAO::ResolveTrackIdOption::UnhideHidden; + if (pSource == nullptr) { + options |= TrackDAO::ResolveTrackIdOption::AddMissing; + } + QList trackIds = m_pTrackCollection->resolveTrackIds(files, options); if (!trackIds.size()) { return false; } diff --git a/src/library/crate/cratetablemodel.cpp b/src/library/crate/cratetablemodel.cpp index ef3e5e57df9..05b59463287 100644 --- a/src/library/crate/cratetablemodel.cpp +++ b/src/library/crate/cratetablemodel.cpp @@ -152,7 +152,9 @@ int CrateTableModel::addTracks(const QModelIndex& index, fileInfoList.append(fileInfo); } - QList trackIds = m_pTrackCollection->getAndEnsureTrackIds(fileInfoList, true); + QList trackIds = m_pTrackCollection->resolveTrackIds(fileInfoList, + TrackDAO::ResolveTrackIdOption::UnhideHidden + | TrackDAO::ResolveTrackIdOption::AddMissing); if (m_pTrackCollection->addCrateTracks(m_selectedCrate, trackIds)) { select(); return trackIds.size(); diff --git a/src/library/dao/trackdao.cpp b/src/library/dao/trackdao.cpp index d15fe064ceb..76362dee0e0 100644 --- a/src/library/dao/trackdao.cpp +++ b/src/library/dao/trackdao.cpp @@ -135,8 +135,8 @@ TrackId TrackDAO::getTrackId(const QString& absoluteFilePath) { return trackId; } -QList TrackDAO::getTrackIds(const QList& files, - bool addMissingTracks) { +QList TrackDAO::resolveTrackIds(const QList& files, + ResolveTrackIdOptions options) { QList trackIds; trackIds.reserve(files.size()); @@ -164,7 +164,7 @@ QList TrackDAO::getTrackIds(const QList& files, LOG_FAILED_QUERY(query); } - if (addMissingTracks) { + if (options & ResolveTrackIdOption::AddMissing) { // Prepare to add tracks to the database. // This also begins an SQL transaction. addTracksPrepare(); diff --git a/src/library/dao/trackdao.h b/src/library/dao/trackdao.h index 52824ad0301..b007dbd9e4c 100644 --- a/src/library/dao/trackdao.h +++ b/src/library/dao/trackdao.h @@ -24,6 +24,14 @@ class LibraryHashDAO; class TrackDAO : public QObject, public virtual DAO, public virtual GlobalTrackCacheRelocator { Q_OBJECT public: + + enum class ResolveTrackIdOption : int { + ResolveOnly = 0, + UnhideHidden = 1, + AddMissing = 2 + }; + Q_DECLARE_FLAGS(ResolveTrackIdOptions, ResolveTrackIdOption) + // The 'config object' is necessary because users decide ID3 tags get // synchronized on track metadata change TrackDAO( @@ -40,7 +48,7 @@ class TrackDAO : public QObject, public virtual DAO, public virtual GlobalTrackC void finish(); TrackId getTrackId(const QString& absoluteFilePath); - QList getTrackIds(const QList& files, bool addMissingTracks); + QList resolveTrackIds(const QList& files, ResolveTrackIdOptions options); QList getTrackIds(const QDir& dir); // WARNING: Only call this from the main thread instance of TrackDAO. @@ -157,4 +165,7 @@ class TrackDAO : public QObject, public virtual DAO, public virtual GlobalTrackC DISALLOW_COPY_AND_ASSIGN(TrackDAO); }; + +Q_DECLARE_OPERATORS_FOR_FLAGS(TrackDAO::ResolveTrackIdOptions) + #endif //TRACKDAO_H diff --git a/src/library/librarytablemodel.cpp b/src/library/librarytablemodel.cpp index 5805125c15c..e3c2059edf1 100644 --- a/src/library/librarytablemodel.cpp +++ b/src/library/librarytablemodel.cpp @@ -65,7 +65,9 @@ int LibraryTableModel::addTracks(const QModelIndex& index, foreach (QString fileLocation, locations) { fileInfoList.append(QFileInfo(fileLocation)); } - QList trackIds = m_pTrackCollection->getAndEnsureTrackIds(fileInfoList, true); + QList trackIds = m_pTrackCollection->resolveTrackIds(fileInfoList, + TrackDAO::ResolveTrackIdOption::UnhideHidden + | TrackDAO::ResolveTrackIdOption::AddMissing); select(); return trackIds.size(); } diff --git a/src/library/mixxxlibraryfeature.cpp b/src/library/mixxxlibraryfeature.cpp index 7eb29f42a4d..cf38c3a8c3b 100644 --- a/src/library/mixxxlibraryfeature.cpp +++ b/src/library/mixxxlibraryfeature.cpp @@ -182,9 +182,9 @@ bool MixxxLibraryFeature::dropAccept(QList urls, QObject* pSource) { return false; } else { QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); - - // Adds track, does not insert duplicates, handles unremoving logic. - QList trackIds = m_pTrackCollection->getAndEnsureTrackIds(files, true); + QList trackIds = m_pTrackCollection->resolveTrackIds(files, + TrackDAO::ResolveTrackIdOption::UnhideHidden + | TrackDAO::ResolveTrackIdOption::AddMissing); return trackIds.size() > 0; } } diff --git a/src/library/playlistfeature.cpp b/src/library/playlistfeature.cpp index 0966fc8b433..5b284030a6c 100644 --- a/src/library/playlistfeature.cpp +++ b/src/library/playlistfeature.cpp @@ -114,12 +114,14 @@ bool PlaylistFeature::dropAcceptChild(const QModelIndex& index, QList urls // If a track is dropped onto a playlist's name, but the track isn't in the // library, then add the track to the library before adding it to the - // playlist. getAndEnsureTrackIds(), does not insert duplicates and handles - // unremove logic. + // playlist. // pSource != nullptr it is a drop from inside Mixxx and indicates all // tracks already in the DB - bool addMissingTracks = (pSource == nullptr); - QList trackIds = m_pTrackCollection->getAndEnsureTrackIds(files, addMissingTracks); + TrackDAO::ResolveTrackIdOptions options = TrackDAO::ResolveTrackIdOption::UnhideHidden; + if (pSource == nullptr) { + options |= TrackDAO::ResolveTrackIdOption::AddMissing; + } + QList trackIds = m_pTrackCollection->resolveTrackIds(files, options); if (!trackIds.size()) { return false; } diff --git a/src/library/playlisttablemodel.cpp b/src/library/playlisttablemodel.cpp index 3b419f889aa..1abe0b666ee 100644 --- a/src/library/playlisttablemodel.cpp +++ b/src/library/playlisttablemodel.cpp @@ -92,7 +92,9 @@ int PlaylistTableModel::addTracks(const QModelIndex& index, fileInfoList.append(fileInfo); } - QList trackIds = m_pTrackCollection->getAndEnsureTrackIds(fileInfoList, true); + QList trackIds = m_pTrackCollection->resolveTrackIds(fileInfoList, + TrackDAO::ResolveTrackIdOption::UnhideHidden + | TrackDAO::ResolveTrackIdOption::AddMissing); int tracksAdded = m_pTrackCollection->getPlaylistDAO().insertTracksIntoPlaylist( trackIds, m_iPlaylistId, position); diff --git a/src/library/trackcollection.cpp b/src/library/trackcollection.cpp index ff68351687c..f2c41811765 100644 --- a/src/library/trackcollection.cpp +++ b/src/library/trackcollection.cpp @@ -87,10 +87,12 @@ void TrackCollection::relocateDirectory(QString oldDir, QString newDir) { GlobalTrackCacheLocker().relocateCachedTracks(&m_trackDao); } -QList TrackCollection::getAndEnsureTrackIds( - const QList& files, bool addMissingTracks) { - QList trackIds = m_trackDao.getTrackIds(files, addMissingTracks); - unhideTracks(trackIds); +QList TrackCollection::resolveTrackIds( + const QList& files, TrackDAO::ResolveTrackIdOptions options) { + QList trackIds = m_trackDao.resolveTrackIds(files, options); + if (options & TrackDAO::ResolveTrackIdOption::UnhideHidden) { + unhideTracks(trackIds); + } return trackIds; } diff --git a/src/library/trackcollection.h b/src/library/trackcollection.h index c880ae54edd..21f18e10355 100644 --- a/src/library/trackcollection.h +++ b/src/library/trackcollection.h @@ -68,7 +68,7 @@ class TrackCollection : public QObject, // This function returns a track ID of all file in the list not already visible, // it adds and unhides the tracks as well. - QList getAndEnsureTrackIds(const QList& files, bool addMissingTracks); + QList resolveTrackIds(const QList& files, TrackDAO::ResolveTrackIdOptions options); bool hideTracks(const QList& trackIds); bool unhideTracks(const QList& trackIds); From 29167403b0e930dde61c2cbe99eab20ad5d2b833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sat, 28 Sep 2019 21:44:02 +0200 Subject: [PATCH 09/13] Add new functions resolveTrackIdsFromUrls() and resolveTrackIdsFromLocations() to remove duplicates --- src/library/analysisfeature.cpp | 7 ++---- src/library/autodj/autodjfeature.cpp | 12 ++--------- src/library/crate/cratefeature.cpp | 12 ++--------- src/library/crate/cratetablemodel.cpp | 11 ++-------- src/library/librarytablemodel.cpp | 9 ++------ src/library/mixxxlibraryfeature.cpp | 6 ++---- src/library/playlistfeature.cpp | 13 ++--------- src/library/playlisttablemodel.cpp | 13 +++-------- src/library/trackcollection.cpp | 31 +++++++++++++++++++++++++++ src/library/trackcollection.h | 7 +++++- 10 files changed, 54 insertions(+), 67 deletions(-) diff --git a/src/library/analysisfeature.cpp b/src/library/analysisfeature.cpp index 058b7bc23e8..d5d9a5c817f 100644 --- a/src/library/analysisfeature.cpp +++ b/src/library/analysisfeature.cpp @@ -193,11 +193,8 @@ void AnalysisFeature::cleanupAnalyzer() { } bool AnalysisFeature::dropAccept(QList urls, QObject* pSource) { - Q_UNUSED(pSource); - QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); - QList trackIds = m_pTrackCollection->resolveTrackIds(files, - TrackDAO::ResolveTrackIdOption::UnhideHidden - | TrackDAO::ResolveTrackIdOption::AddMissing); + QList trackIds = m_pTrackCollection->resolveTrackIdsFromUrls(urls, + !pSource); analyzeTracks(trackIds); return trackIds.size() > 0; } diff --git a/src/library/autodj/autodjfeature.cpp b/src/library/autodj/autodjfeature.cpp index 1d4eed271fa..a378ab15c06 100644 --- a/src/library/autodj/autodjfeature.cpp +++ b/src/library/autodj/autodjfeature.cpp @@ -138,21 +138,13 @@ void AutoDJFeature::activate() { } bool AutoDJFeature::dropAccept(QList urls, QObject* pSource) { - QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); - if (!files.size()) { - return false; - } - // If a track is dropped onto the Auto DJ tree node, but the track isn't in the // library, then add the track to the library before adding it to the // Auto DJ playlist. // pSource != nullptr it is a drop from inside Mixxx and indicates all // tracks already in the DB - TrackDAO::ResolveTrackIdOptions options = TrackDAO::ResolveTrackIdOption::UnhideHidden; - if (pSource == nullptr) { - options |= TrackDAO::ResolveTrackIdOption::AddMissing; - } - QList trackIds = m_pTrackCollection->resolveTrackIds(files, options); + QList trackIds = m_pTrackCollection->resolveTrackIdsFromUrls(urls, + !pSource); if (!trackIds.size()) { return false; } diff --git a/src/library/crate/cratefeature.cpp b/src/library/crate/cratefeature.cpp index 14d375b6e9b..073fd6ca75e 100644 --- a/src/library/crate/cratefeature.cpp +++ b/src/library/crate/cratefeature.cpp @@ -203,21 +203,13 @@ bool CrateFeature::dropAcceptChild(const QModelIndex& index, QList urls, VERIFY_OR_DEBUG_ASSERT(crateId.isValid()) { return false; } - QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); - if (!files.size()) { - return false; - } - // If a track is dropped onto a crate's name, but the track isn't in the // library, then add the track to the library before adding it to the // playlist. // pSource != nullptr it is a drop from inside Mixxx and indicates all // tracks already in the DB - TrackDAO::ResolveTrackIdOptions options = TrackDAO::ResolveTrackIdOption::UnhideHidden; - if (pSource == nullptr) { - options |= TrackDAO::ResolveTrackIdOption::AddMissing; - } - QList trackIds = m_pTrackCollection->resolveTrackIds(files, options); + QList trackIds = m_pTrackCollection->resolveTrackIdsFromUrls(urls, + !pSource); if (!trackIds.size()) { return false; } diff --git a/src/library/crate/cratetablemodel.cpp b/src/library/crate/cratetablemodel.cpp index 05b59463287..94fe753c489 100644 --- a/src/library/crate/cratetablemodel.cpp +++ b/src/library/crate/cratetablemodel.cpp @@ -146,15 +146,8 @@ int CrateTableModel::addTracks(const QModelIndex& index, Q_UNUSED(index); // If a track is dropped but it isn't in the library, then add it because // the user probably dropped a file from outside Mixxx into this crate. - QList fileInfoList; - foreach(QString fileLocation, locations) { - QFileInfo fileInfo(fileLocation); - fileInfoList.append(fileInfo); - } - - QList trackIds = m_pTrackCollection->resolveTrackIds(fileInfoList, - TrackDAO::ResolveTrackIdOption::UnhideHidden - | TrackDAO::ResolveTrackIdOption::AddMissing); + QList trackIds = m_pTrackCollection->resolveTrackIdsFromLocations( + locations); if (m_pTrackCollection->addCrateTracks(m_selectedCrate, trackIds)) { select(); return trackIds.size(); diff --git a/src/library/librarytablemodel.cpp b/src/library/librarytablemodel.cpp index e3c2059edf1..22342f7962f 100644 --- a/src/library/librarytablemodel.cpp +++ b/src/library/librarytablemodel.cpp @@ -61,13 +61,8 @@ void LibraryTableModel::setTableModel(int id) { int LibraryTableModel::addTracks(const QModelIndex& index, const QList& locations) { Q_UNUSED(index); - QList fileInfoList; - foreach (QString fileLocation, locations) { - fileInfoList.append(QFileInfo(fileLocation)); - } - QList trackIds = m_pTrackCollection->resolveTrackIds(fileInfoList, - TrackDAO::ResolveTrackIdOption::UnhideHidden - | TrackDAO::ResolveTrackIdOption::AddMissing); + QList trackIds = m_pTrackCollection->resolveTrackIdsFromLocations( + locations); select(); return trackIds.size(); } diff --git a/src/library/mixxxlibraryfeature.cpp b/src/library/mixxxlibraryfeature.cpp index cf38c3a8c3b..b8fde12d239 100644 --- a/src/library/mixxxlibraryfeature.cpp +++ b/src/library/mixxxlibraryfeature.cpp @@ -181,10 +181,8 @@ bool MixxxLibraryFeature::dropAccept(QList urls, QObject* pSource) { if (pSource) { return false; } else { - QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); - QList trackIds = m_pTrackCollection->resolveTrackIds(files, - TrackDAO::ResolveTrackIdOption::UnhideHidden - | TrackDAO::ResolveTrackIdOption::AddMissing); + QList trackIds = m_pTrackCollection->resolveTrackIdsFromUrls( + urls, true); return trackIds.size() > 0; } } diff --git a/src/library/playlistfeature.cpp b/src/library/playlistfeature.cpp index 5b284030a6c..e8253266dad 100644 --- a/src/library/playlistfeature.cpp +++ b/src/library/playlistfeature.cpp @@ -106,22 +106,13 @@ bool PlaylistFeature::dropAcceptChild(const QModelIndex& index, QList urls VERIFY_OR_DEBUG_ASSERT(playlistId >= 0) { return false; } - - QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); - if (!files.size()) { - return false; - } - // If a track is dropped onto a playlist's name, but the track isn't in the // library, then add the track to the library before adding it to the // playlist. // pSource != nullptr it is a drop from inside Mixxx and indicates all // tracks already in the DB - TrackDAO::ResolveTrackIdOptions options = TrackDAO::ResolveTrackIdOption::UnhideHidden; - if (pSource == nullptr) { - options |= TrackDAO::ResolveTrackIdOption::AddMissing; - } - QList trackIds = m_pTrackCollection->resolveTrackIds(files, options); + QList trackIds = m_pTrackCollection->resolveTrackIdsFromUrls(urls, + !pSource); if (!trackIds.size()) { return false; } diff --git a/src/library/playlisttablemodel.cpp b/src/library/playlisttablemodel.cpp index 1abe0b666ee..d6ac44e729d 100644 --- a/src/library/playlisttablemodel.cpp +++ b/src/library/playlisttablemodel.cpp @@ -78,6 +78,9 @@ int PlaylistTableModel::addTracks(const QModelIndex& index, return 0; } + QList trackIds = m_pTrackCollection->resolveTrackIdsFromLocations( + locations); + const int positionColumn = fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION); int position = index.sibling(index.row(), positionColumn).data().toInt(); @@ -86,16 +89,6 @@ int PlaylistTableModel::addTracks(const QModelIndex& index, position = rowCount() + 1; } - QList fileInfoList; - foreach (QString fileLocation, locations) { - QFileInfo fileInfo(fileLocation); - fileInfoList.append(fileInfo); - } - - QList trackIds = m_pTrackCollection->resolveTrackIds(fileInfoList, - TrackDAO::ResolveTrackIdOption::UnhideHidden - | TrackDAO::ResolveTrackIdOption::AddMissing); - int tracksAdded = m_pTrackCollection->getPlaylistDAO().insertTracksIntoPlaylist( trackIds, m_iPlaylistId, position); diff --git a/src/library/trackcollection.cpp b/src/library/trackcollection.cpp index f2c41811765..cafc9e3c051 100644 --- a/src/library/trackcollection.cpp +++ b/src/library/trackcollection.cpp @@ -9,6 +9,7 @@ #include "util/db/sqltransaction.h" #include "util/assert.h" +#include "util/dnd.h" namespace { @@ -96,6 +97,36 @@ QList TrackCollection::resolveTrackIds( return trackIds; } +QList TrackCollection::resolveTrackIdsFromUrls( + const QList& urls, bool addMissing) { + QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); + if (!files.size()) { + return QList(); + } + + TrackDAO::ResolveTrackIdOptions options = + TrackDAO::ResolveTrackIdOption::UnhideHidden; + if (addMissing) { + options |= TrackDAO::ResolveTrackIdOption::AddMissing; + } + return resolveTrackIds(files, options); +} + +QList TrackCollection::resolveTrackIdsFromLocations( + const QList& locations) { + QList fileInfoList; + foreach(QString fileLocation, locations) { + QFileInfo fileInfo(fileLocation); + fileInfoList.append(fileInfo); + } + return resolveTrackIds(fileInfoList, + TrackDAO::ResolveTrackIdOption::UnhideHidden + | TrackDAO::ResolveTrackIdOption::AddMissing); +} + +QList resolveTrackIdsFromUrls(const QList& urls, + TrackDAO::ResolveTrackIdOptions options); + bool TrackCollection::hideTracks(const QList& trackIds) { DEBUG_ASSERT(QApplication::instance()->thread() == QThread::currentThread()); diff --git a/src/library/trackcollection.h b/src/library/trackcollection.h index 21f18e10355..8afd7aded38 100644 --- a/src/library/trackcollection.h +++ b/src/library/trackcollection.h @@ -68,7 +68,12 @@ class TrackCollection : public QObject, // This function returns a track ID of all file in the list not already visible, // it adds and unhides the tracks as well. - QList resolveTrackIds(const QList& files, TrackDAO::ResolveTrackIdOptions options); + QList resolveTrackIds(const QList &files, + TrackDAO::ResolveTrackIdOptions options); + QList resolveTrackIdsFromUrls(const QList& urls, + bool addMissing); + QList resolveTrackIdsFromLocations( + const QList& locations); bool hideTracks(const QList& trackIds); bool unhideTracks(const QList& trackIds); From ea855d60db8767efe57c8ee8352e755f6c64e74a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sat, 28 Sep 2019 22:49:27 +0200 Subject: [PATCH 10/13] rename options -> flags --- src/library/dao/trackdao.cpp | 4 ++-- src/library/dao/trackdao.h | 9 +++++---- src/library/trackcollection.cpp | 20 ++++++++++---------- src/library/trackcollection.h | 2 +- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/library/dao/trackdao.cpp b/src/library/dao/trackdao.cpp index 76362dee0e0..b29656208f8 100644 --- a/src/library/dao/trackdao.cpp +++ b/src/library/dao/trackdao.cpp @@ -136,7 +136,7 @@ TrackId TrackDAO::getTrackId(const QString& absoluteFilePath) { } QList TrackDAO::resolveTrackIds(const QList& files, - ResolveTrackIdOptions options) { + ResolveTrackIdFlags flags) { QList trackIds; trackIds.reserve(files.size()); @@ -164,7 +164,7 @@ QList TrackDAO::resolveTrackIds(const QList& files, LOG_FAILED_QUERY(query); } - if (options & ResolveTrackIdOption::AddMissing) { + if (flags & ResolveTrackIdFlag::AddMissing) { // Prepare to add tracks to the database. // This also begins an SQL transaction. addTracksPrepare(); diff --git a/src/library/dao/trackdao.h b/src/library/dao/trackdao.h index b007dbd9e4c..7632a0468f3 100644 --- a/src/library/dao/trackdao.h +++ b/src/library/dao/trackdao.h @@ -25,12 +25,12 @@ class TrackDAO : public QObject, public virtual DAO, public virtual GlobalTrackC Q_OBJECT public: - enum class ResolveTrackIdOption : int { + enum class ResolveTrackIdFlag : int { ResolveOnly = 0, UnhideHidden = 1, AddMissing = 2 }; - Q_DECLARE_FLAGS(ResolveTrackIdOptions, ResolveTrackIdOption) + Q_DECLARE_FLAGS(ResolveTrackIdFlags, ResolveTrackIdFlag) // The 'config object' is necessary because users decide ID3 tags get // synchronized on track metadata change @@ -48,7 +48,8 @@ class TrackDAO : public QObject, public virtual DAO, public virtual GlobalTrackC void finish(); TrackId getTrackId(const QString& absoluteFilePath); - QList resolveTrackIds(const QList& files, ResolveTrackIdOptions options); + QList resolveTrackIds(const QList &files, + ResolveTrackIdFlags flags); QList getTrackIds(const QDir& dir); // WARNING: Only call this from the main thread instance of TrackDAO. @@ -166,6 +167,6 @@ class TrackDAO : public QObject, public virtual DAO, public virtual GlobalTrackC }; -Q_DECLARE_OPERATORS_FOR_FLAGS(TrackDAO::ResolveTrackIdOptions) +Q_DECLARE_OPERATORS_FOR_FLAGS(TrackDAO::ResolveTrackIdFlags) #endif //TRACKDAO_H diff --git a/src/library/trackcollection.cpp b/src/library/trackcollection.cpp index cafc9e3c051..a8b029899a7 100644 --- a/src/library/trackcollection.cpp +++ b/src/library/trackcollection.cpp @@ -89,9 +89,9 @@ void TrackCollection::relocateDirectory(QString oldDir, QString newDir) { } QList TrackCollection::resolveTrackIds( - const QList& files, TrackDAO::ResolveTrackIdOptions options) { - QList trackIds = m_trackDao.resolveTrackIds(files, options); - if (options & TrackDAO::ResolveTrackIdOption::UnhideHidden) { + const QList& files, TrackDAO::ResolveTrackIdFlags flags) { + QList trackIds = m_trackDao.resolveTrackIds(files, flags); + if (flags & TrackDAO::ResolveTrackIdFlag::UnhideHidden) { unhideTracks(trackIds); } return trackIds; @@ -104,12 +104,12 @@ QList TrackCollection::resolveTrackIdsFromUrls( return QList(); } - TrackDAO::ResolveTrackIdOptions options = - TrackDAO::ResolveTrackIdOption::UnhideHidden; + TrackDAO::ResolveTrackIdFlags flags = + TrackDAO::ResolveTrackIdFlag::UnhideHidden; if (addMissing) { - options |= TrackDAO::ResolveTrackIdOption::AddMissing; + flags |= TrackDAO::ResolveTrackIdFlag::AddMissing; } - return resolveTrackIds(files, options); + return resolveTrackIds(files, flags); } QList TrackCollection::resolveTrackIdsFromLocations( @@ -120,12 +120,12 @@ QList TrackCollection::resolveTrackIdsFromLocations( fileInfoList.append(fileInfo); } return resolveTrackIds(fileInfoList, - TrackDAO::ResolveTrackIdOption::UnhideHidden - | TrackDAO::ResolveTrackIdOption::AddMissing); + TrackDAO::ResolveTrackIdFlag::UnhideHidden + | TrackDAO::ResolveTrackIdFlag::AddMissing); } QList resolveTrackIdsFromUrls(const QList& urls, - TrackDAO::ResolveTrackIdOptions options); + TrackDAO::ResolveTrackIdFlags flags); bool TrackCollection::hideTracks(const QList& trackIds) { DEBUG_ASSERT(QApplication::instance()->thread() == QThread::currentThread()); diff --git a/src/library/trackcollection.h b/src/library/trackcollection.h index 8afd7aded38..3f9e36f9bd9 100644 --- a/src/library/trackcollection.h +++ b/src/library/trackcollection.h @@ -69,7 +69,7 @@ class TrackCollection : public QObject, // This function returns a track ID of all file in the list not already visible, // it adds and unhides the tracks as well. QList resolveTrackIds(const QList &files, - TrackDAO::ResolveTrackIdOptions options); + TrackDAO::ResolveTrackIdFlags flags); QList resolveTrackIdsFromUrls(const QList& urls, bool addMissing); QList resolveTrackIdsFromLocations( From ad73dbafd53c11b928efeae7446780276e4bfb7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sat, 28 Sep 2019 22:52:56 +0200 Subject: [PATCH 11/13] predefere isEmpty() over !size() --- src/library/trackcollection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/library/trackcollection.cpp b/src/library/trackcollection.cpp index a8b029899a7..0db796a9928 100644 --- a/src/library/trackcollection.cpp +++ b/src/library/trackcollection.cpp @@ -100,7 +100,7 @@ QList TrackCollection::resolveTrackIds( QList TrackCollection::resolveTrackIdsFromUrls( const QList& urls, bool addMissing) { QList files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); - if (!files.size()) { + if (files.isEmpty()) { return QList(); } From ec0b35478434a053bafcaa21fb159b0c415ba069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sat, 28 Sep 2019 23:13:03 +0200 Subject: [PATCH 12/13] rename onHideTracks to hideTracks --- src/library/dao/trackdao.cpp | 2 +- src/library/dao/trackdao.h | 2 +- src/library/trackcollection.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/library/dao/trackdao.cpp b/src/library/dao/trackdao.cpp index b29656208f8..9359506d90a 100644 --- a/src/library/dao/trackdao.cpp +++ b/src/library/dao/trackdao.cpp @@ -744,7 +744,7 @@ TrackPointer TrackDAO::addSingleTrack(const QFileInfo& fileInfo, bool unremove) return pTrack; } -bool TrackDAO::onHidingTracks( +bool TrackDAO::hideTracks( const QList& trackIds) { QStringList idList; for (const auto& trackId: trackIds) { diff --git a/src/library/dao/trackdao.h b/src/library/dao/trackdao.h index 7632a0468f3..dcb0fefaac3 100644 --- a/src/library/dao/trackdao.h +++ b/src/library/dao/trackdao.h @@ -65,7 +65,7 @@ class TrackDAO : public QObject, public virtual DAO, public virtual GlobalTrackC TrackId addTracksAddTrack(const TrackPointer& pTrack, bool unremove); void addTracksFinish(bool rollback = false); - bool onHidingTracks( + bool hideTracks( const QList& trackIds); void afterHidingTracks( const QList& trackIds); diff --git a/src/library/trackcollection.cpp b/src/library/trackcollection.cpp index 0db796a9928..35af06d177f 100644 --- a/src/library/trackcollection.cpp +++ b/src/library/trackcollection.cpp @@ -171,7 +171,7 @@ bool TrackCollection::hideTracks(const QList& trackIds) { VERIFY_OR_DEBUG_ASSERT(transaction) { return false; } - VERIFY_OR_DEBUG_ASSERT(m_trackDao.onHidingTracks(trackIds)) { + VERIFY_OR_DEBUG_ASSERT(m_trackDao.hideTracks(trackIds)) { return false; } VERIFY_OR_DEBUG_ASSERT(transaction.commit()) { From 04b26e4160d22249bedfab87902ccafda60115e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Thu, 3 Oct 2019 22:46:20 +0200 Subject: [PATCH 13/13] change remaining !size() to isEmpty() --- src/library/autodj/autodjfeature.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/library/autodj/autodjfeature.cpp b/src/library/autodj/autodjfeature.cpp index a378ab15c06..140347ad4f4 100644 --- a/src/library/autodj/autodjfeature.cpp +++ b/src/library/autodj/autodjfeature.cpp @@ -145,7 +145,7 @@ bool AutoDJFeature::dropAccept(QList urls, QObject* pSource) { // tracks already in the DB QList trackIds = m_pTrackCollection->resolveTrackIdsFromUrls(urls, !pSource); - if (!trackIds.size()) { + if (trackIds.isEmpty()) { return false; }