mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 11:35:24 +01:00
Make sure only one playlist can have the "current" song
This commit is contained in:
parent
e515724bf7
commit
f17a422797
@ -119,6 +119,12 @@ void PlaylistManager::SetCurrentPlaylist(int index) {
|
||||
|
||||
void PlaylistManager::SetActivePlaylist(int index) {
|
||||
Q_ASSERT(index >= 0 && index < playlists_.count());
|
||||
|
||||
// Kinda a hack: unset the current item from the old active playlist before
|
||||
// setting the new one
|
||||
if (active_ != -1)
|
||||
active()->set_current_index(-1);
|
||||
|
||||
active_ = index;
|
||||
emit ActiveChanged(current());
|
||||
}
|
||||
|
@ -475,8 +475,10 @@ void MainWindow::AddFilesToPlaylist(bool clear_first, const QList<QUrl>& urls) {
|
||||
|
||||
QModelIndex playlist_index = playlists_->current()->InsertPaths(urls);
|
||||
|
||||
if (playlist_index.isValid() && player_->GetState() != Engine::Playing)
|
||||
if (playlist_index.isValid() && player_->GetState() != Engine::Playing) {
|
||||
playlists_->SetActivePlaylist(playlists_->current_index());
|
||||
player_->PlayAt(playlist_index.row(), Engine::First, true);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::ReportError(const QString& message) {
|
||||
@ -565,6 +567,7 @@ void MainWindow::PlayIndex(const QModelIndex& index) {
|
||||
if (!index.isValid())
|
||||
return;
|
||||
|
||||
playlists_->SetActivePlaylist(playlists_->current_index());
|
||||
player_->PlayAt(index.row(), Engine::Manual, true);
|
||||
}
|
||||
|
||||
@ -591,8 +594,10 @@ void MainWindow::AddLibraryItemToPlaylist(bool clear_first, const QModelIndex& i
|
||||
QModelIndex first_song = playlists_->current()->InsertLibraryItems(
|
||||
library_->model()->GetChildSongs(idx));
|
||||
|
||||
if (first_song.isValid() && player_->GetState() != Engine::Playing)
|
||||
if (first_song.isValid() && player_->GetState() != Engine::Playing) {
|
||||
playlists_->SetActivePlaylist(playlists_->current_index());
|
||||
player_->PlayAt(first_song.row(), Engine::First, true);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::VolumeWheelEvent(int delta) {
|
||||
@ -707,23 +712,29 @@ void MainWindow::RadioDoubleClick(const QModelIndex& index) {
|
||||
playlists_->current()->dropMimeData(data.get(), Qt::CopyAction, -1, 0, QModelIndex());
|
||||
|
||||
QModelIndex first_song = playlists_->current()->index(0, 0);
|
||||
if (first_song.isValid() && player_->GetState() != Engine::Playing)
|
||||
if (first_song.isValid() && player_->GetState() != Engine::Playing) {
|
||||
playlists_->SetActivePlaylist(playlists_->current_index());
|
||||
player_->PlayAt(first_song.row(), Engine::First, true);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::InsertRadioItem(RadioItem* item) {
|
||||
QModelIndex first_song = playlists_->current()->InsertRadioStations(
|
||||
QList<RadioItem*>() << item);
|
||||
|
||||
if (first_song.isValid() && player_->GetState() != Engine::Playing)
|
||||
if (first_song.isValid() && player_->GetState() != Engine::Playing) {
|
||||
playlists_->SetActivePlaylist(playlists_->current_index());
|
||||
player_->PlayAt(first_song.row(), Engine::First, true);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::InsertRadioItems(const PlaylistItemList& items) {
|
||||
QModelIndex first_song = playlists_->current()->InsertItems(items);
|
||||
|
||||
if (first_song.isValid() && player_->GetState() != Engine::Playing)
|
||||
if (first_song.isValid() && player_->GetState() != Engine::Playing) {
|
||||
playlists_->SetActivePlaylist(playlists_->current_index());
|
||||
player_->PlayAt(first_song.row(), Engine::First, true);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::PlaylistRightClick(const QPoint& global_pos, const QModelIndex& index) {
|
||||
@ -794,6 +805,7 @@ void MainWindow::PlaylistPlay() {
|
||||
if (playlists_->current()->current_index() == playlist_menu_index_.row()) {
|
||||
player_->PlayPause();
|
||||
} else {
|
||||
playlists_->SetActivePlaylist(playlists_->current_index());
|
||||
player_->PlayAt(playlist_menu_index_.row(), Engine::Manual, true);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user