fix: only set queue context when a track is actually played
Opening a playlist/album no longer resets the queue. The queue context is now set inside onDoubleClicked and the "Play Now" context menu action, using the current (possibly sorted) model order at the moment of play. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -44,31 +44,23 @@ Tracks::Tracks(QobuzBackend *backend, PlayQueue *queue, QWidget *parent)
|
||||
void Tracks::loadTracks(const QJsonArray &tracks)
|
||||
{
|
||||
m_model->setTracks(tracks, false, /*useSequential=*/true);
|
||||
m_queue->setContext(tracks, 0);
|
||||
syncQueueToModel();
|
||||
}
|
||||
|
||||
void Tracks::loadAlbum(const QJsonObject &album)
|
||||
{
|
||||
const QJsonArray items = album["tracks"].toObject()["items"].toArray();
|
||||
m_model->setTracks(items); // album: use track_number
|
||||
m_queue->setContext(items, 0);
|
||||
syncQueueToModel();
|
||||
}
|
||||
|
||||
void Tracks::loadPlaylist(const QJsonObject &playlist)
|
||||
{
|
||||
const QJsonArray items = playlist["tracks"].toObject()["items"].toArray();
|
||||
m_model->setTracks(items, /*usePosition=*/true);
|
||||
m_queue->setContext(items, 0);
|
||||
syncQueueToModel();
|
||||
}
|
||||
|
||||
void Tracks::loadSearchTracks(const QJsonArray &tracks)
|
||||
{
|
||||
m_model->setTracks(tracks, false, /*useSequential=*/true);
|
||||
m_queue->setContext(tracks, 0);
|
||||
syncQueueToModel();
|
||||
}
|
||||
|
||||
void Tracks::setPlayingTrackId(qint64 id)
|
||||
@@ -86,7 +78,7 @@ void Tracks::onDoubleClicked(const QModelIndex &index)
|
||||
{
|
||||
const qint64 id = m_model->data(index, TrackListModel::TrackIdRole).toLongLong();
|
||||
if (id > 0) {
|
||||
m_queue->setCurrentById(id);
|
||||
m_queue->setContext(m_model->currentTracksJson(), index.row());
|
||||
emit playTrackRequested(id);
|
||||
}
|
||||
}
|
||||
@@ -108,8 +100,9 @@ void Tracks::onContextMenu(const QPoint &pos)
|
||||
auto *addFav = menu.addAction(QIcon(":/res/icons/starred-symbolic.svg"), tr("Add to favorites"));
|
||||
auto *remFav = menu.addAction(QIcon(":/res/icons/non-starred-symbolic.svg"), tr("Remove from favorites"));
|
||||
|
||||
connect(playNow, &QAction::triggered, this, [this, id] {
|
||||
m_queue->setCurrentById(id);
|
||||
const int row = index.row();
|
||||
connect(playNow, &QAction::triggered, this, [this, id, row] {
|
||||
m_queue->setContext(m_model->currentTracksJson(), row);
|
||||
emit playTrackRequested(id);
|
||||
});
|
||||
connect(playNext, &QAction::triggered, this, [this, trackJson] {
|
||||
|
||||
Reference in New Issue
Block a user