New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the track order during drag and drop Lp1829601 #2237
Changes from 7 commits
af5a36f
5ad6d78
901095c
0e9b727
af85c1c
5eb8ac0
acb8444
29b81a7
2916740
ea855d6
ad73dba
ec0b354
04b26e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,26 +138,24 @@ void AutoDJFeature::activate() { | |
} | ||
|
||
bool AutoDJFeature::dropAccept(QList<QUrl> 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<QFileInfo> files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); | ||
QList<TrackId> trackIds; | ||
if (pSource) { | ||
trackIds = m_pTrackCollection->getTrackDAO().getTrackIds(files); | ||
m_pTrackCollection->unhideTracks(trackIds); | ||
} else { | ||
trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files, true); | ||
if (!files.size()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isEmpty() |
||
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<TrackId> trackIds = m_pTrackCollection->getAndEnsureTrackIds(files, addMissingTracks); | ||
if (!trackIds.size()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isEmpty() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping |
||
return false; | ||
} | ||
|
||
// Return whether the tracks were appended. | ||
// Return whether appendTracksToPlaylist succeeded. | ||
return m_playlistDao.appendTracksToPlaylist(trackIds, m_iAutoDJPlaylistId); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,26 +200,26 @@ void updateTreeItemForTrackSelection( | |
bool CrateFeature::dropAcceptChild(const QModelIndex& index, QList<QUrl> urls, | ||
QObject* pSource) { | ||
CrateId crateId(crateIdFromIndex(index)); | ||
if (!crateId.isValid()) { | ||
VERIFY_OR_DEBUG_ASSERT(crateId.isValid()) { | ||
return false; | ||
} | ||
QList<QFileInfo> files = DragAndDropHelper::supportedTracksFromUrls(urls, false, true); | ||
QList<TrackId> trackIds; | ||
if (pSource) { | ||
trackIds = m_pTrackCollection->getTrackDAO().getTrackIds(files); | ||
m_pTrackCollection->unhideTracks(trackIds); | ||
} else { | ||
// Adds track, does not insert duplicates, handles unremoving logic. | ||
trackIds = m_pTrackCollection->getTrackDAO().addMultipleTracks(files, true); | ||
} | ||
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()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isEmpty() |
||
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<TrackId> trackIds = m_pTrackCollection->getAndEnsureTrackIds(files, addMissingTracks); | ||
if (!trackIds.size()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isEmpty() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping |
||
return false; | ||
} | ||
|
||
m_pTrackCollection->addCrateTracks(crateId, trackIds); | ||
return true; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dropAccept()/dropAcceptChild() contain a lot of duplicated code (AutoDJ/Crates/Playlist). Is It possible to extract this code into a function?