diff options
author | Uwe Klotz <uwe_klotz@web.de> | 2017-02-02 00:34:46 +0100 |
---|---|---|
committer | Uwe Klotz <uwe_klotz@web.de> | 2017-02-02 00:34:46 +0100 |
commit | d0c7e55f0a92115315057cbf2039c88020105efb (patch) | |
tree | 950486dfff6775e635fc0142a3322a55161303b2 /src/library | |
parent | f8f426ec1b0a63d7073e10fcb057cfd322c8ed4e (diff) | |
parent | 6a7884fd10dd51345a56a103f798501b9d20de86 (diff) |
Merge branch 'master' into cratestorage
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/dao/playlistdao.cpp | 46 | ||||
-rw-r--r-- | src/library/dao/playlistdao.h | 9 | ||||
-rw-r--r-- | src/library/dlganalysis.cpp | 8 | ||||
-rw-r--r-- | src/library/dlganalysis.h | 3 | ||||
-rw-r--r-- | src/library/librarycontrol.cpp | 2 | ||||
-rw-r--r-- | src/library/libraryview.h | 3 | ||||
-rw-r--r-- | src/library/recording/dlgrecording.cpp | 8 | ||||
-rw-r--r-- | src/library/recording/dlgrecording.h | 3 |
8 files changed, 62 insertions, 20 deletions
diff --git a/src/library/dao/playlistdao.cpp b/src/library/dao/playlistdao.cpp index 50aa06c9c8..665bb28ac9 100644 --- a/src/library/dao/playlistdao.cpp +++ b/src/library/dao/playlistdao.cpp @@ -246,6 +246,23 @@ bool PlaylistDAO::isPlaylistLocked(const int playlistId) const { return false; } +bool PlaylistDAO::removeTracksFromPlaylist(const int playlistId, const int startIndex) { + // Retain the first track if it is loaded in a deck + ScopedTransaction transaction(m_database); + QSqlQuery query(m_database); + query.prepare("DELETE FROM PlaylistTracks " + "WHERE playlist_id=:id AND position>=:pos"); + query.bindValue(":id", playlistId); + query.bindValue(":pos", startIndex); + if (!query.exec()) { + LOG_FAILED_QUERY(query); + return false; + } + transaction.commit(); + emit(changed(playlistId)); + return true; +} + bool PlaylistDAO::appendTracksToPlaylist(const QList<TrackId>& trackIds, const int playlistId) { // qDebug() << "PlaylistDAO::appendTracksToPlaylist" // << QThread::currentThread() << m_database.connectionName(); @@ -1011,21 +1028,28 @@ void PlaylistDAO::setAutoDJProcessor(AutoDJProcessor* pAutoDJProcessor) { m_pAutoDJProcessor = pAutoDJProcessor; } -void PlaylistDAO::sendToAutoDJ(const QList<TrackId>& trackIds, bool bTop) { +void PlaylistDAO::sendToAutoDJ(const QList<TrackId>& trackIds, AutoDJSendLoc loc) { int iAutoDJPlaylistId = getPlaylistIdFromName(AUTODJ_TABLE); if (iAutoDJPlaylistId == -1) { return; } - if (bTop) { - int position = 1; - if (m_pAutoDJProcessor && m_pAutoDJProcessor->nextTrackLoaded()) { - // Load track to position two because position one is - // already loaded to the player - position = 2; - } - insertTracksIntoPlaylist(trackIds, iAutoDJPlaylistId, position); - } else { - appendTracksToPlaylist(trackIds, iAutoDJPlaylistId); + // If the first track is already loaded to the player, + // alter the playlist only below the first track + int position = + (m_pAutoDJProcessor && m_pAutoDJProcessor->nextTrackLoaded()) ? 2 : 1; + + switch (loc) { + case AutoDJSendLoc::TOP: + insertTracksIntoPlaylist(trackIds, iAutoDJPlaylistId, position); + break; + case AutoDJSendLoc::BOTTOM: + appendTracksToPlaylist(trackIds, iAutoDJPlaylistId); + break; + case AutoDJSendLoc::REPLACE: + if (removeTracksFromPlaylist(iAutoDJPlaylistId, position)) { + appendTracksToPlaylist(trackIds, iAutoDJPlaylistId); + } + break; } } diff --git a/src/library/dao/playlistdao.h b/src/library/dao/playlistdao.h index dd5a221493..6347955963 100644 --- a/src/library/dao/playlistdao.h +++ b/src/library/dao/playlistdao.h @@ -40,6 +40,12 @@ class PlaylistDAO : public QObject, public virtual DAO { PLHT_UNKNOWN = -1 }; + enum class AutoDJSendLoc { + TOP, + BOTTOM, + REPLACE, + }; + PlaylistDAO(QSqlDatabase& database); virtual ~PlaylistDAO(); @@ -108,7 +114,7 @@ class PlaylistDAO : public QObject, public virtual DAO { void getPlaylistsTrackIsIn(TrackId trackId, QSet<int>* playlistSet) const; void setAutoDJProcessor(AutoDJProcessor* pAutoDJProcessor); - void sendToAutoDJ(const QList<TrackId>& trackIds, bool bTop); + void sendToAutoDJ(const QList<TrackId>& trackIds, AutoDJSendLoc loc); signals: void added(int playlistId); @@ -120,6 +126,7 @@ class PlaylistDAO : public QObject, public virtual DAO { void lockChanged(int playlistId); private: + bool removeTracksFromPlaylist(const int playlistId, const int startIndex); void removeTracksFromPlaylistsInner(const QStringList& idList); void searchForDuplicateTrack(const int fromPosition, const int toPosition, diff --git a/src/library/dlganalysis.cpp b/src/library/dlganalysis.cpp index 6ce0526b4f..52e27740a3 100644 --- a/src/library/dlganalysis.cpp +++ b/src/library/dlganalysis.cpp @@ -89,15 +89,19 @@ void DlgAnalysis::loadSelectedTrackToGroup(QString group, bool play) { m_pAnalysisLibraryTableView->loadSelectedTrackToGroup(group, play); } -void DlgAnalysis::slotSendToAutoDJ() { +void DlgAnalysis::slotSendToAutoDJBottom() { // append to auto DJ - m_pAnalysisLibraryTableView->slotSendToAutoDJ(); + m_pAnalysisLibraryTableView->slotSendToAutoDJBottom(); } void DlgAnalysis::slotSendToAutoDJTop() { m_pAnalysisLibraryTableView->slotSendToAutoDJTop(); } +void DlgAnalysis::slotSendToAutoDJReplace() { + m_pAnalysisLibraryTableView->slotSendToAutoDJReplace(); +} + void DlgAnalysis::moveSelection(int delta) { m_pAnalysisLibraryTableView->moveSelection(delta); } diff --git a/src/library/dlganalysis.h b/src/library/dlganalysis.h index 012fadaffa..67c4a67664 100644 --- a/src/library/dlganalysis.h +++ b/src/library/dlganalysis.h @@ -25,8 +25,9 @@ class DlgAnalysis : public QWidget, public Ui::DlgAnalysis, public virtual Libra bool hasFocus() const override; void loadSelectedTrack() override; void loadSelectedTrackToGroup(QString group, bool play) override; - void slotSendToAutoDJ() override; + void slotSendToAutoDJBottom() override; void slotSendToAutoDJTop() override; + void slotSendToAutoDJReplace() override; void moveSelection(int delta) override; inline const QString currentSearch() { return m_pAnalysisLibraryTableModel->currentSearch(); diff --git a/src/library/librarycontrol.cpp b/src/library/librarycontrol.cpp index 2a0c239272..d3d13e3472 100644 --- a/src/library/librarycontrol.cpp +++ b/src/library/librarycontrol.cpp @@ -285,7 +285,7 @@ void LibraryControl::slotAutoDjAddBottom(double v) { if (!activeView) { return; } - activeView->slotSendToAutoDJ(); + activeView->slotSendToAutoDJBottom(); } } diff --git a/src/library/libraryview.h b/src/library/libraryview.h index 1e5a5c03a2..7be3d9d1e5 100644 --- a/src/library/libraryview.h +++ b/src/library/libraryview.h @@ -22,8 +22,9 @@ class LibraryView { // track. Does nothing otherwise. virtual void loadSelectedTrack() {}; - virtual void slotSendToAutoDJ() {}; + virtual void slotSendToAutoDJBottom() {}; virtual void slotSendToAutoDJTop() {}; + virtual void slotSendToAutoDJReplace() {}; // If applicable, requests that the LibraryView load the selected track to // the specified group. Does nothing otherwise. diff --git a/src/library/recording/dlgrecording.cpp b/src/library/recording/dlgrecording.cpp index d55326b90c..e23af25779 100644 --- a/src/library/recording/dlgrecording.cpp +++ b/src/library/recording/dlgrecording.cpp @@ -89,14 +89,18 @@ void DlgRecording::loadSelectedTrack() { m_pTrackTableView->loadSelectedTrack(); } -void DlgRecording::slotSendToAutoDJ() { - m_pTrackTableView->slotSendToAutoDJ(); +void DlgRecording::slotSendToAutoDJBottom() { + m_pTrackTableView->slotSendToAutoDJBottom(); } void DlgRecording::slotSendToAutoDJTop() { m_pTrackTableView->slotSendToAutoDJTop(); } +void DlgRecording::slotSendToAutoDJReplace() { + m_pTrackTableView->slotSendToAutoDJReplace(); +} + void DlgRecording::loadSelectedTrackToGroup(QString group, bool play) { m_pTrackTableView->loadSelectedTrackToGroup(group, play); } diff --git a/src/library/recording/dlgrecording.h b/src/library/recording/dlgrecording.h index caf8fd0547..56c8d9e4aa 100644 --- a/src/library/recording/dlgrecording.h +++ b/src/library/recording/dlgrecording.h @@ -28,8 +28,9 @@ class DlgRecording : public QWidget, public Ui::DlgRecording, public virtual Lib void onShow() override; bool hasFocus() const override; void loadSelectedTrack() override; - void slotSendToAutoDJ() override; + void slotSendToAutoDJBottom() override; void slotSendToAutoDJTop() override; + void slotSendToAutoDJReplace() override; void loadSelectedTrackToGroup(QString group, bool play) override; void moveSelection(int delta) override; inline const QString currentSearch() { return m_proxyModel.currentSearch(); } |