Refactor Tidal, Spotify, Qobuz, Subsonic and cover providers
Use common HTTP, Json and OAuthenticator class
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2020-2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2020-2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -89,6 +89,14 @@ CoversSettingsPage::CoversSettingsPage(SettingsDialog *dialog, const SharedPtr<C
|
||||
|
||||
CoversSettingsPage::~CoversSettingsPage() { delete ui_; }
|
||||
|
||||
void CoversSettingsPage::showEvent(QShowEvent *e) {
|
||||
|
||||
ProvidersCurrentItemChanged(ui_->providers->currentItem(), nullptr);
|
||||
|
||||
SettingsPage::showEvent(e);
|
||||
|
||||
}
|
||||
|
||||
void CoversSettingsPage::Load() {
|
||||
|
||||
ui_->providers->clear();
|
||||
@@ -206,7 +214,7 @@ void CoversSettingsPage::ProvidersCurrentItemChanged(QListWidgetItem *item_curre
|
||||
|
||||
if (item_previous) {
|
||||
CoverProvider *provider = cover_providers_->ProviderByName(item_previous->text());
|
||||
if (provider && provider->AuthenticationRequired()) DisconnectAuthentication(provider);
|
||||
if (provider && provider->authentication_required()) DisconnectAuthentication(provider);
|
||||
}
|
||||
|
||||
if (item_current) {
|
||||
@@ -215,21 +223,21 @@ void CoversSettingsPage::ProvidersCurrentItemChanged(QListWidgetItem *item_curre
|
||||
ui_->providers_down->setEnabled(row != ui_->providers->count() - 1);
|
||||
CoverProvider *provider = cover_providers_->ProviderByName(item_current->text());
|
||||
if (provider) {
|
||||
if (provider->AuthenticationRequired()) {
|
||||
if (provider->name() == "Tidal"_L1 && !provider->IsAuthenticated()) {
|
||||
if (provider->authentication_required()) {
|
||||
if (provider->name() == "Tidal"_L1 && !provider->authenticated()) {
|
||||
DisableAuthentication();
|
||||
ui_->label_auth_info->setText(tr("Use Tidal settings to authenticate."));
|
||||
}
|
||||
else if (provider->name() == "Spotify"_L1 && !provider->IsAuthenticated()) {
|
||||
else if (provider->name() == "Spotify"_L1 && !provider->authenticated()) {
|
||||
DisableAuthentication();
|
||||
ui_->label_auth_info->setText(tr("Use Spotify settings to authenticate."));
|
||||
}
|
||||
else if (provider->name() == "Qobuz"_L1 && !provider->IsAuthenticated()) {
|
||||
else if (provider->name() == "Qobuz"_L1 && !provider->authenticated()) {
|
||||
DisableAuthentication();
|
||||
ui_->label_auth_info->setText(tr("Use Qobuz settings to authenticate."));
|
||||
}
|
||||
else {
|
||||
ui_->login_state->SetLoggedIn(provider->IsAuthenticated() ? LoginStateWidget::State::LoggedIn : LoginStateWidget::State::LoggedOut);
|
||||
ui_->login_state->SetLoggedIn(provider->authenticated() ? LoginStateWidget::State::LoggedIn : LoginStateWidget::State::LoggedOut);
|
||||
ui_->button_authenticate->setEnabled(true);
|
||||
ui_->button_authenticate->show();
|
||||
ui_->login_state->show();
|
||||
@@ -331,7 +339,7 @@ void CoversSettingsPage::LogoutClicked() {
|
||||
if (!ui_->providers->currentItem()) return;
|
||||
CoverProvider *provider = cover_providers_->ProviderByName(ui_->providers->currentItem()->text());
|
||||
if (!provider) return;
|
||||
provider->Deauthenticate();
|
||||
provider->ClearSession();
|
||||
|
||||
if (provider->name() == "Tidal"_L1) {
|
||||
DisableAuthentication();
|
||||
@@ -365,7 +373,7 @@ void CoversSettingsPage::AuthenticationSuccess() {
|
||||
|
||||
}
|
||||
|
||||
void CoversSettingsPage::AuthenticationFailure(const QStringList &errors) {
|
||||
void CoversSettingsPage::AuthenticationFailure(const QString &error) {
|
||||
|
||||
CoverProvider *provider = qobject_cast<CoverProvider*>(sender());
|
||||
if (!provider) return;
|
||||
@@ -373,7 +381,7 @@ void CoversSettingsPage::AuthenticationFailure(const QStringList &errors) {
|
||||
|
||||
if (!isVisible() || !ui_->providers->currentItem() || ui_->providers->currentItem()->text() != provider->name()) return;
|
||||
|
||||
QMessageBox::warning(this, tr("Authentication failed"), errors.join(u'\n'));
|
||||
QMessageBox::warning(this, tr("Authentication failed"), error);
|
||||
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::State::LoggedOut);
|
||||
ui_->button_authenticate->setEnabled(true);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2020-2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2020-2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "settings/settingspage.h"
|
||||
|
||||
class QListWidgetItem;
|
||||
class QShowEvent;
|
||||
|
||||
class CoverProviders;
|
||||
class CoverProvider;
|
||||
@@ -46,6 +47,9 @@ class CoversSettingsPage : public SettingsPage {
|
||||
void Load() override;
|
||||
void Save() override;
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *e) override;
|
||||
|
||||
private:
|
||||
void NoProviderSelected();
|
||||
void ProvidersMove(const int d);
|
||||
@@ -65,7 +69,7 @@ class CoversSettingsPage : public SettingsPage {
|
||||
void AuthenticateClicked();
|
||||
void LogoutClicked();
|
||||
void AuthenticationSuccess();
|
||||
void AuthenticationFailure(const QStringList &errors);
|
||||
void AuthenticationFailure(const QString &error);
|
||||
void CoverSaveInAlbumDirChanged();
|
||||
void TypesCurrentItemChanged(QListWidgetItem *item_current, QListWidgetItem *item_previous);
|
||||
void TypesItemSelectionChanged();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2019-2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -70,6 +70,13 @@ QobuzSettingsPage::QobuzSettingsPage(SettingsDialog *dialog, const SharedPtr<Qob
|
||||
|
||||
QobuzSettingsPage::~QobuzSettingsPage() { delete ui_; }
|
||||
|
||||
void QobuzSettingsPage::showEvent(QShowEvent *e) {
|
||||
|
||||
ui_->login_state->SetLoggedIn(service_->authenticated() ? LoginStateWidget::State::LoggedIn : LoginStateWidget::State::LoggedOut);
|
||||
SettingsPage::showEvent(e);
|
||||
|
||||
}
|
||||
|
||||
void QobuzSettingsPage::Load() {
|
||||
|
||||
Settings s;
|
||||
@@ -157,7 +164,7 @@ bool QobuzSettingsPage::eventFilter(QObject *object, QEvent *event) {
|
||||
|
||||
void QobuzSettingsPage::LogoutClicked() {
|
||||
|
||||
service_->Logout();
|
||||
service_->ClearSession();
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::State::LoggedOut);
|
||||
ui_->button_login->setEnabled(true);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2019-2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "settings/settingspage.h"
|
||||
|
||||
class QShowEvent;
|
||||
class QEvent;
|
||||
class SettingsDialog;
|
||||
class QobuzService;
|
||||
@@ -43,6 +44,9 @@ class QobuzSettingsPage : public SettingsPage {
|
||||
|
||||
bool eventFilter(QObject *object, QEvent *event) override;
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *e) override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void Login(const QString &username, const QString &password, const QString &token);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2022-2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2022-2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -81,6 +81,13 @@ SpotifySettingsPage::SpotifySettingsPage(SettingsDialog *dialog, const SharedPtr
|
||||
|
||||
SpotifySettingsPage::~SpotifySettingsPage() { delete ui_; }
|
||||
|
||||
void SpotifySettingsPage::showEvent(QShowEvent *e) {
|
||||
|
||||
ui_->login_state->SetLoggedIn(service_->authenticated() ? LoginStateWidget::State::LoggedIn : LoginStateWidget::State::LoggedOut);
|
||||
SettingsPage::showEvent(e);
|
||||
|
||||
}
|
||||
|
||||
void SpotifySettingsPage::Load() {
|
||||
|
||||
Settings s;
|
||||
@@ -139,7 +146,7 @@ bool SpotifySettingsPage::eventFilter(QObject *object, QEvent *event) {
|
||||
|
||||
void SpotifySettingsPage::LogoutClicked() {
|
||||
|
||||
service_->Deauthenticate();
|
||||
service_->ClearSession();
|
||||
ui_->button_login->setEnabled(true);
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::State::LoggedOut);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2022-2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2022-2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "settings/settingspage.h"
|
||||
|
||||
class QEvent;
|
||||
class QShowEvent;
|
||||
class SpotifyService;
|
||||
class SettingsDialog;
|
||||
class Ui_SpotifySettingsPage;
|
||||
@@ -45,6 +46,9 @@ class SpotifySettingsPage : public SettingsPage {
|
||||
|
||||
bool eventFilter(QObject *object, QEvent *event) override;
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *e) override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void Authorize();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2018-2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -81,6 +81,13 @@ TidalSettingsPage::TidalSettingsPage(SettingsDialog *dialog, SharedPtr<TidalServ
|
||||
|
||||
TidalSettingsPage::~TidalSettingsPage() { delete ui_; }
|
||||
|
||||
void TidalSettingsPage::showEvent(QShowEvent *e) {
|
||||
|
||||
ui_->login_state->SetLoggedIn(service_->authenticated() ? LoginStateWidget::State::LoggedIn : LoginStateWidget::State::LoggedOut);
|
||||
SettingsPage::showEvent(e);
|
||||
|
||||
}
|
||||
|
||||
void TidalSettingsPage::Load() {
|
||||
|
||||
Settings s;
|
||||
@@ -164,7 +171,7 @@ bool TidalSettingsPage::eventFilter(QObject *object, QEvent *event) {
|
||||
|
||||
void TidalSettingsPage::LogoutClicked() {
|
||||
|
||||
service_->Logout();
|
||||
service_->ClearSession();
|
||||
ui_->button_login->setEnabled(true);
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::State::LoggedOut);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* Copyright 2018-2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "settings/settingspage.h"
|
||||
|
||||
class QShowEvent;
|
||||
class QEvent;
|
||||
class TidalService;
|
||||
class SettingsDialog;
|
||||
@@ -45,6 +46,9 @@ class TidalSettingsPage : public SettingsPage {
|
||||
|
||||
bool eventFilter(QObject *object, QEvent *event) override;
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *e) override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void Authorize(const QString &client_id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user