Skip to content

Commit

Permalink
PlaylistDAO: add getNextPlaylist(), to be used for History feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Jan 28, 2023
1 parent 399a8ee commit 16c7af7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/library/dao/playlistdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,26 @@ int PlaylistDAO::getPreviousPlaylist(const int currentPlaylistId, HiddenType hid
return kInvalidPlaylistId;
}

int PlaylistDAO::getNextPlaylist(const int currentPlaylistId, HiddenType hidden) const {
QSqlQuery query(m_database);
query.prepare(QStringLiteral(
"SELECT max(id) as id FROM Playlists "
"WHERE id > :id AND hidden = :hidden"));
query.bindValue(":id", currentPlaylistId);
query.bindValue(":hidden", hidden);

if (!query.exec()) {
LOG_FAILED_QUERY(query);
return kInvalidPlaylistId;
}

// Get the id of the lowest playlist
if (query.next()) {
return query.value(query.record().indexOf("id")).toInt();
}
return kInvalidPlaylistId;
}

bool PlaylistDAO::copyPlaylistTracks(const int sourcePlaylistID, const int targetPlaylistID) {
// Start the transaction
ScopedTransaction transaction(m_database);
Expand Down
3 changes: 3 additions & 0 deletions src/library/dao/playlistdao.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ class PlaylistDAO : public QObject, public virtual DAO {
// Get the preceding playlist of currentPlaylistId with the HiddenType
// hidden. Returns -1 if no such playlist exists.
int getPreviousPlaylist(const int currentPlaylistId, HiddenType hidden) const;
// Get the following playlist of currentPlaylistId with the HiddenType
// hidden. Returns -1 if no such playlist exists.
int getNextPlaylist(const int currentPlaylistId, HiddenType hidden) const;
// Append all the tracks in the source playlist to the target playlist.
bool copyPlaylistTracks(const int sourcePlaylistID, const int targetPlaylistID);
// Returns the number of tracks in the given playlist.
Expand Down

0 comments on commit 16c7af7

Please sign in to comment.