Add back Tidal support

This commit is contained in:
Jonas Kvinge
2020-04-13 19:04:06 +02:00
parent e738f2bc9f
commit d90aecb164
38 changed files with 5404 additions and 6 deletions

View File

@@ -73,6 +73,9 @@
#ifdef HAVE_SUBSONIC
# include "subsonicsettingspage.h"
#endif
#ifdef HAVE_TIDAL
# include "tidalsettingspage.h"
#endif
#include "ui_settingsdialog.h"
@@ -145,12 +148,16 @@ SettingsDialog::SettingsDialog(Application *app, QMainWindow *mainwindow, QWidge
AddPage(Page_Moodbar, new MoodbarSettingsPage(this), iface);
#endif
#if defined(HAVE_SUBSONIC)
#if defined(HAVE_SUBSONIC) || defined(HAVE_TIDAL)
QTreeWidgetItem *streaming = AddCategory(tr("Streaming"));
#endif
#ifdef HAVE_SUBSONIC
AddPage(Page_Subsonic, new SubsonicSettingsPage(this), streaming);
#endif
#ifdef HAVE_TIDAL
AddPage(Page_Tidal, new TidalSettingsPage(this), streaming);
#endif
// List box
connect(ui_->list, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), SLOT(CurrentItemChanged(QTreeWidgetItem*)));

View File

@@ -86,7 +86,8 @@ class SettingsDialog : public QDialog {
Page_Proxy,
Page_Scrobbler,
Page_Moodbar,
Page_Subsonic
Page_Subsonic,
Page_Tidal,
};
enum Role {

View File

@@ -0,0 +1,205 @@
/*
* Strawberry Music Player
* Copyright 2018, 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Strawberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <QObject>
#include <QVariant>
#include <QByteArray>
#include <QString>
#include <QSettings>
#include <QCheckBox>
#include <QComboBox>
#include <QLineEdit>
#include <QPushButton>
#include <QSpinBox>
#include <QMessageBox>
#include <QEvent>
#include "settingsdialog.h"
#include "tidalsettingspage.h"
#include "ui_tidalsettingspage.h"
#include "core/application.h"
#include "core/iconloader.h"
#include "internet/internetservices.h"
#include "tidal/tidalservice.h"
#include "widgets/loginstatewidget.h"
const char *TidalSettingsPage::kSettingsGroup = "Tidal";
TidalSettingsPage::TidalSettingsPage(SettingsDialog *parent)
: SettingsPage(parent),
ui_(new Ui::TidalSettingsPage),
service_(dialog()->app()->internet_services()->Service<TidalService>()) {
ui_->setupUi(this);
setWindowIcon(IconLoader::Load("tidal"));
connect(ui_->button_login, SIGNAL(clicked()), SLOT(LoginClicked()));
connect(ui_->login_state, SIGNAL(LogoutClicked()), SLOT(LogoutClicked()));
connect(ui_->oauth, SIGNAL(toggled(bool)), SLOT(OAuthClicked(bool)));
connect(this, SIGNAL(Login()), service_, SLOT(StartAuthorisation()));
connect(this, SIGNAL(Login(QString, QString, QString)), service_, SLOT(SendLogin(QString, QString, QString)));
connect(service_, SIGNAL(LoginFailure(QString)), SLOT(LoginFailure(QString)));
connect(service_, SIGNAL(LoginSuccess()), SLOT(LoginSuccess()));
dialog()->installEventFilter(this);
ui_->quality->addItem("Low", "LOW");
ui_->quality->addItem("High", "HIGH");
ui_->quality->addItem("Lossless", "LOSSLESS");
ui_->quality->addItem("Hi resolution", "HI_RES");
ui_->coversize->addItem("160x160", "160x160");
ui_->coversize->addItem("320x320", "320x320");
ui_->coversize->addItem("640x640", "640x640");
ui_->coversize->addItem("750x750", "750x750");
ui_->coversize->addItem("1280x1280", "1280x1280");
ui_->streamurl->addItem("streamurl", StreamUrlMethod_StreamUrl);
ui_->streamurl->addItem("urlpostpaywall", StreamUrlMethod_UrlPostPaywall);
ui_->streamurl->addItem("playbackinfopostpaywall", StreamUrlMethod_PlaybackInfoPostPaywall);
}
TidalSettingsPage::~TidalSettingsPage() { delete ui_; }
void TidalSettingsPage::Load() {
QSettings s;
s.beginGroup(kSettingsGroup);
ui_->enable->setChecked(s.value("enabled", false).toBool());
ui_->oauth->setChecked(s.value("oauth", false).toBool());
ui_->client_id->setText(s.value("client_id").toString());
ui_->api_token->setText(s.value("api_token").toString());
ui_->username->setText(s.value("username").toString());
QByteArray password = s.value("password").toByteArray();
if (password.isEmpty()) ui_->password->clear();
else ui_->password->setText(QString::fromUtf8(QByteArray::fromBase64(password)));
dialog()->ComboBoxLoadFromSettings(s, ui_->quality, "quality", "HIGH");
ui_->searchdelay->setValue(s.value("searchdelay", 1500).toInt());
ui_->artistssearchlimit->setValue(s.value("artistssearchlimit", 4).toInt());
ui_->albumssearchlimit->setValue(s.value("albumssearchlimit", 10).toInt());
ui_->songssearchlimit->setValue(s.value("songssearchlimit", 10).toInt());
ui_->checkbox_fetchalbums->setChecked(s.value("fetchalbums", false).toBool());
ui_->checkbox_download_album_covers->setChecked(s.value("downloadalbumcovers", true).toBool());
dialog()->ComboBoxLoadFromSettings(s, ui_->coversize, "coversize", "320x320");
StreamUrlMethod stream_url = static_cast<StreamUrlMethod>(s.value("streamurl").toInt());
int i = ui_->streamurl->findData(stream_url);
if (i == -1) i = ui_->streamurl->findData(StreamUrlMethod_StreamUrl);
ui_->streamurl->setCurrentIndex(i);
s.endGroup();
OAuthClicked(ui_->oauth->isChecked());
if (service_->authenticated()) ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn);
}
void TidalSettingsPage::Save() {
QSettings s;
s.beginGroup(kSettingsGroup);
s.setValue("enabled", ui_->enable->isChecked());
s.setValue("oauth", ui_->oauth->isChecked());
s.setValue("client_id", ui_->client_id->text());
s.setValue("api_token", ui_->api_token->text());
s.setValue("username", ui_->username->text());
s.setValue("password", QString::fromUtf8(ui_->password->text().toUtf8().toBase64()));
s.setValue("quality", ui_->quality->itemData(ui_->quality->currentIndex()));
s.setValue("searchdelay", ui_->searchdelay->value());
s.setValue("artistssearchlimit", ui_->artistssearchlimit->value());
s.setValue("albumssearchlimit", ui_->albumssearchlimit->value());
s.setValue("songssearchlimit", ui_->songssearchlimit->value());
s.setValue("fetchalbums", ui_->checkbox_fetchalbums->isChecked());
s.setValue("downloadalbumcovers", ui_->checkbox_download_album_covers->isChecked());
s.setValue("coversize", ui_->coversize->itemData(ui_->coversize->currentIndex()));
s.setValue("streamurl", ui_->streamurl->itemData(ui_->streamurl->currentIndex()));
s.endGroup();
service_->ReloadSettings();
}
void TidalSettingsPage::LoginClicked() {
if (ui_->oauth->isChecked()) {
if (ui_->client_id->text().isEmpty()) {
QMessageBox::critical(this, tr("Configuration incomplete"), tr("Missing Tidal client ID."));
return;
}
emit Login();
}
else {
if (ui_->api_token->text().isEmpty() || ui_->username->text().isEmpty() || ui_->password->text().isEmpty()) {
QMessageBox::critical(this, tr("Configuration incomplete"), tr("Missing API token, username or password."));
return;
}
emit Login(ui_->api_token->text(), ui_->username->text(), ui_->password->text());
}
ui_->button_login->setEnabled(false);
}
bool TidalSettingsPage::eventFilter(QObject *object, QEvent *event) {
if (object == dialog() && event->type() == QEvent::Enter) {
ui_->button_login->setEnabled(true);
return false;
}
return SettingsPage::eventFilter(object, event);
}
void TidalSettingsPage::OAuthClicked(const bool enabled) {
ui_->client_id->setEnabled(enabled);
ui_->api_token->setEnabled(!enabled);
ui_->username->setEnabled(!enabled);
ui_->password->setEnabled(!enabled);
}
void TidalSettingsPage::LogoutClicked() {
service_->Logout();
ui_->button_login->setEnabled(true);
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut);
}
void TidalSettingsPage::LoginSuccess() {
if (!this->isVisible()) return;
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn);
ui_->button_login->setEnabled(true);
}
void TidalSettingsPage::LoginFailure(const QString &failure_reason) {
if (!this->isVisible()) return;
QMessageBox::warning(this, tr("Authentication failed"), failure_reason);
ui_->button_login->setEnabled(true);
}

View File

@@ -0,0 +1,71 @@
/*
* Strawberry Music Player
* Copyright 2018, 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Strawberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef TIDALSETTINGSPAGE_H
#define TIDALSETTINGSPAGE_H
#include "config.h"
#include <QObject>
#include <QString>
#include "settings/settingspage.h"
class QEvent;
class TidalService;
class SettingsDialog;
class Ui_TidalSettingsPage;
class TidalSettingsPage : public SettingsPage {
Q_OBJECT
public:
explicit TidalSettingsPage(SettingsDialog* parent = nullptr);
~TidalSettingsPage();
static const char *kSettingsGroup;
enum StreamUrlMethod {
StreamUrlMethod_StreamUrl,
StreamUrlMethod_UrlPostPaywall,
StreamUrlMethod_PlaybackInfoPostPaywall,
};
void Load();
void Save();
bool eventFilter(QObject *object, QEvent *event);
signals:
void Login();
void Login(const QString &api_token, const QString &username, const QString &password);
private slots:
void OAuthClicked(const bool enabled);
void LoginClicked();
void LogoutClicked();
void LoginSuccess();
void LoginFailure(const QString &failure_reason);
private:
Ui_TidalSettingsPage* ui_;
TidalService *service_;
};
#endif

View File

@@ -0,0 +1,357 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TidalSettingsPage</class>
<widget class="QWidget" name="TidalSettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>715</width>
<height>836</height>
</rect>
</property>
<property name="windowTitle">
<string>Tidal</string>
</property>
<layout class="QVBoxLayout" name="layout_tidalsettingspage">
<item>
<widget class="QCheckBox" name="enable">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_warning">
<property name="text">
<string>Tidal support is not official and requires a API token from a registered application to work. We can't help you getting these.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="margin">
<number>10</number>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="credential_group">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Authentication</string>
</property>
<layout class="QFormLayout" name="layout_credential_group">
<item row="0" column="0">
<widget class="QCheckBox" name="oauth">
<property name="text">
<string>Use OAuth</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_client_id">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Client ID</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="client_id"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_api_token">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>API Token</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="api_token">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_username">
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="username"/>
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_password">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="password">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_login">
<property name="text">
<string>Login</string>
</property>
</widget>
</item>
<item>
<widget class="LoginStateWidget" name="login_state" native="true"/>
</item>
<item>
<widget class="QGroupBox" name="groupbox_preferences">
<property name="title">
<string>Preferences</string>
</property>
<layout class="QFormLayout" name="layout_preferences">
<item row="0" column="0">
<widget class="QLabel" name="label_quality">
<property name="text">
<string>Audio quality</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="quality"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_searchdelay">
<property name="text">
<string>Search delay</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="searchdelay">
<property name="suffix">
<string>ms</string>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
<property name="singleStep">
<number>50</number>
</property>
<property name="value">
<number>1500</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_artistssearchlimit">
<property name="text">
<string>Artists search limit</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="artistssearchlimit">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>50</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_albumssearchlimit">
<property name="text">
<string>Albums search limit</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="albumssearchlimit">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>1000</number>
</property>
<property name="value">
<number>50</number>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_songssearchlimit">
<property name="text">
<string>Songs search limit</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="checkbox_download_album_covers">
<property name="text">
<string>Download album covers</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="checkbox_fetchalbums">
<property name="text">
<string>Fetch entire albums when searching songs</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QComboBox" name="coversize"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_coversize">
<property name="text">
<string>Album cover size</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="songssearchlimit">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>1000</number>
</property>
<property name="value">
<number>50</number>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_streamurl">
<property name="text">
<string>Stream URL method</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QComboBox" name="streamurl"/>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="spacer_middle">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>30</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="layout_bottom">
<item>
<spacer name="spacer_bottom">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_tidal">
<property name="minimumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="pixmap">
<pixmap resource="../../data/icons.qrc">:/icons/64x64/tidal.png</pixmap>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LoginStateWidget</class>
<extends>QWidget</extends>
<header>widgets/loginstatewidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>enable</tabstop>
<tabstop>oauth</tabstop>
<tabstop>client_id</tabstop>
<tabstop>api_token</tabstop>
<tabstop>username</tabstop>
<tabstop>password</tabstop>
<tabstop>button_login</tabstop>
<tabstop>quality</tabstop>
<tabstop>searchdelay</tabstop>
<tabstop>artistssearchlimit</tabstop>
<tabstop>albumssearchlimit</tabstop>
<tabstop>songssearchlimit</tabstop>
<tabstop>checkbox_download_album_covers</tabstop>
<tabstop>checkbox_fetchalbums</tabstop>
<tabstop>coversize</tabstop>
<tabstop>streamurl</tabstop>
</tabstops>
<resources>
<include location="../../data/data.qrc"/>
<include location="../../data/icons.qrc"/>
</resources>
<connections/>
</ui>