diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index e1248547b..c37467913 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -173,6 +173,7 @@ # include "constants/tidalsettings.h" #endif #ifdef HAVE_SPOTIFY +# include "spotify/spotifyservice.h" # include "constants/spotifysettings.h" #endif #ifdef HAVE_QOBUZ @@ -772,6 +773,9 @@ MainWindow::MainWindow(Application *app, QObject::connect(spotify_view_->songs_collection_view(), &StreamingCollectionView::AddToPlaylistSignal, this, &MainWindow::AddToPlaylist); QObject::connect(spotify_view_->search_view(), &StreamingSearchView::OpenSettingsDialog, this, &MainWindow::OpenServiceSettingsDialog); QObject::connect(spotify_view_->search_view(), &StreamingSearchView::AddToPlaylist, this, &MainWindow::AddToPlaylist); + if (SpotifyServicePtr spotifyservice = app_->streaming_services()->Service()) { + QObject::connect(&*spotifyservice, &SpotifyService::UpdateSpotifyAccessToken, &*app_->player()->engine(), &EngineBase::UpdateSpotifyAccessToken); + } #endif QObject::connect(radio_view_, &RadioViewContainer::Refresh, &*app_->radio_services(), &RadioServices::RefreshChannels); diff --git a/src/engine/enginebase.cpp b/src/engine/enginebase.cpp index 9d2b45224..41e74ed98 100644 --- a/src/engine/enginebase.cpp +++ b/src/engine/enginebase.cpp @@ -256,3 +256,19 @@ bool EngineBase::ValidOutput(const QString &output) { return (true); } + +void EngineBase::UpdateSpotifyAccessToken(const QString &spotify_access_token) { + +#ifdef HAVE_SPOTIFY + + spotify_access_token_ = spotify_access_token; + + SetSpotifyAccessToken(); + +#else + + Q_UNUSED(spotify_access_token) + +#endif // HAVE_SPOTIFY + +} diff --git a/src/engine/enginebase.h b/src/engine/enginebase.h index f1b990c3d..821ad90a9 100644 --- a/src/engine/enginebase.h +++ b/src/engine/enginebase.h @@ -127,6 +127,7 @@ class EngineBase : public QObject { virtual void ReloadSettings(); void UpdateVolume(const uint volume); void EmitAboutToFinish(); + void UpdateSpotifyAccessToken(const QString &spotify_access_token); public: // Simple accessors @@ -175,6 +176,11 @@ class EngineBase : public QObject { void Finished(); + private: +#ifdef HAVE_SPOTIFY + virtual void SetSpotifyAccessToken() {} +#endif + protected: bool playbin3_enabled_; bool exclusive_mode_; diff --git a/src/engine/gstengine.cpp b/src/engine/gstengine.cpp index 7b65a2f25..e9b80bef3 100644 --- a/src/engine/gstengine.cpp +++ b/src/engine/gstengine.cpp @@ -517,10 +517,20 @@ bool GstEngine::ExclusiveModeSupport(const QString &output) const { void GstEngine::ReloadSettings() { +#ifdef HAVE_SPOTIFY + const QString old_spotify_access_token = spotify_access_token_; +#endif + EngineBase::ReloadSettings(); if (output_.isEmpty()) output_ = QLatin1String(kAutoSink); +#ifdef HAVE_SPOTIFY + if (current_pipeline_ && old_spotify_access_token != spotify_access_token_) { + current_pipeline_->set_spotify_access_token(spotify_access_token_); + } +#endif + } void GstEngine::ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format) { @@ -1199,3 +1209,13 @@ bool GstEngine::AnyExclusivePipelineActive() const { return (current_pipeline_ && current_pipeline_->exclusive_mode()) || OldExclusivePipelineActive(); } + +#ifdef HAVE_SPOTIFY +void GstEngine::SetSpotifyAccessToken() { + + if (current_pipeline_) { + current_pipeline_->set_spotify_access_token(spotify_access_token_); + } + +} +#endif // HAVE_SPOTIFY diff --git a/src/engine/gstengine.h b/src/engine/gstengine.h index 1b3ecf05f..661a49ce1 100644 --- a/src/engine/gstengine.h +++ b/src/engine/gstengine.h @@ -146,6 +146,10 @@ class GstEngine : public EngineBase, public GstBufferConsumer { bool OldExclusivePipelineActive() const; bool AnyExclusivePipelineActive() const; +#ifdef HAVE_SPOTIFY + void SetSpotifyAccessToken() override; +#endif + private: SharedPtr task_manager_; GstDiscoverer *discoverer_; diff --git a/src/spotify/spotifyservice.cpp b/src/spotify/spotifyservice.cpp index 752e43d77..b777e8ca3 100644 --- a/src/spotify/spotifyservice.cpp +++ b/src/spotify/spotifyservice.cpp @@ -226,14 +226,15 @@ void SpotifyService::ClearSession() { void SpotifyService::OAuthFinished(const bool success, const QString &error) { if (success) { - Q_EMIT LoginFinished(true); Q_EMIT LoginSuccess(); + Q_EMIT UpdateSpotifyAccessToken(oauth_->access_token()); } else { Q_EMIT LoginFailure(error); - Q_EMIT LoginFinished(false); } + Q_EMIT LoginFinished(success); + } void SpotifyService::GetArtists() { diff --git a/src/spotify/spotifyservice.h b/src/spotify/spotifyservice.h index a1d50f4e8..7826a34ce 100644 --- a/src/spotify/spotifyservice.h +++ b/src/spotify/spotifyservice.h @@ -89,6 +89,9 @@ class SpotifyService : public StreamingService { CollectionFilter *albums_collection_filter_model() override { return albums_collection_model_->filter(); } CollectionFilter *songs_collection_filter_model() override { return songs_collection_model_->filter(); } + Q_SIGNALS: + void UpdateSpotifyAccessToken(const QString &access_token); + public Q_SLOTS: void Authenticate(); void ClearSession();