Fix resume playback on startup
This commit is contained in:
@@ -1339,6 +1339,8 @@ void Playlist::ItemsLoaded(QFuture<PlaylistItemList> future) {
|
||||
QtConcurrent::run(this, &Playlist::InvalidateDeletedSongs);
|
||||
}
|
||||
|
||||
emit PlaylistLoaded();
|
||||
|
||||
}
|
||||
|
||||
static bool DescendingIntLessThan(int a, int b) { return a > b; }
|
||||
|
||||
@@ -300,6 +300,7 @@ class Playlist : public QAbstractListModel {
|
||||
|
||||
signals:
|
||||
void RestoreFinished();
|
||||
void PlaylistLoaded();
|
||||
void CurrentSongChanged(const Song &metadata);
|
||||
void EditingFinished(const QModelIndex &index);
|
||||
void PlayRequested(const QModelIndex &index);
|
||||
|
||||
@@ -68,7 +68,8 @@ PlaylistManager::PlaylistManager(Application *app, QObject *parent)
|
||||
parser_(nullptr),
|
||||
playlist_container_(nullptr),
|
||||
current_(-1),
|
||||
active_(-1)
|
||||
active_(-1),
|
||||
playlists_loading_(0)
|
||||
{
|
||||
connect(app_->player(), SIGNAL(Paused()), SLOT(SetActivePaused()));
|
||||
connect(app_->player(), SIGNAL(Playing()), SLOT(SetActivePlaying()));
|
||||
@@ -93,7 +94,9 @@ void PlaylistManager::Init(CollectionBackend *collection_backend, PlaylistBacken
|
||||
connect(collection_backend_, SIGNAL(SongsStatisticsChanged(SongList)), SLOT(SongsDiscovered(SongList)));
|
||||
|
||||
for (const PlaylistBackend::Playlist &p : playlist_backend->GetAllOpenPlaylists()) {
|
||||
AddPlaylist(p.id, p.name, p.special_type, p.ui_path, p.favorite);
|
||||
playlists_loading_++;
|
||||
Playlist *ret = AddPlaylist(p.id, p.name, p.special_type, p.ui_path, p.favorite);
|
||||
connect(ret, SIGNAL(PlaylistLoaded()), SLOT(PlaylistLoaded()));
|
||||
}
|
||||
|
||||
// If no playlist exists then make a new one
|
||||
@@ -103,6 +106,16 @@ void PlaylistManager::Init(CollectionBackend *collection_backend, PlaylistBacken
|
||||
|
||||
}
|
||||
|
||||
void PlaylistManager::PlaylistLoaded() {
|
||||
|
||||
Playlist *playlist = qobject_cast<Playlist*>(sender());
|
||||
if (!playlist) return;
|
||||
disconnect(playlist, SIGNAL(PlaylistLoaded()), this, SLOT(PlaylistLoaded()));
|
||||
playlists_loading_--;
|
||||
if (playlists_loading_ == 0) emit AllPlaylistsLoaded();
|
||||
|
||||
}
|
||||
|
||||
QList<Playlist*> PlaylistManager::GetAllPlaylists() const {
|
||||
|
||||
QList<Playlist*> result;
|
||||
@@ -359,8 +372,7 @@ void PlaylistManager::SetActivePlaylist(int id) {
|
||||
|
||||
Q_ASSERT(playlists_.contains(id));
|
||||
|
||||
// Kinda a hack: unset the current item from the old active playlist before
|
||||
// setting the new one
|
||||
// Kinda a hack: unset the current item from the old active playlist before setting the new one
|
||||
if (active_ != -1 && active_ != id) active()->set_current_row(-1);
|
||||
|
||||
active_ = id;
|
||||
|
||||
@@ -104,6 +104,7 @@ public slots:
|
||||
|
||||
signals:
|
||||
void PlaylistManagerInitialized();
|
||||
void AllPlaylistsLoaded();
|
||||
|
||||
void PlaylistAdded(int id, const QString &name, bool favorite);
|
||||
void PlaylistDeleted(int id);
|
||||
@@ -213,6 +214,7 @@ class PlaylistManager : public PlaylistManagerInterface {
|
||||
void UpdateSummaryText();
|
||||
void SongsDiscovered(const SongList& songs);
|
||||
void ItemsLoadedForSavePlaylist(QFuture<SongList> future, const QString& filename, Playlist::Path path_type);
|
||||
void PlaylistLoaded();
|
||||
|
||||
private:
|
||||
Playlist *AddPlaylist(int id, const QString& name, const QString &special_type, const QString& ui_path, bool favorite);
|
||||
@@ -237,6 +239,7 @@ class PlaylistManager : public PlaylistManagerInterface {
|
||||
|
||||
int current_;
|
||||
int active_;
|
||||
int playlists_loading_;
|
||||
};
|
||||
|
||||
#endif // PLAYLISTMANAGER_H
|
||||
|
||||
Reference in New Issue
Block a user